Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

vba - Refresh MS Access Form/Query Based On Combobox Value

Pretty simple explanation. I have a table with 10 entries, 5 entries with the year 2010 and 5 entries with 2011 in a column.

In the query I have, I use Like *2010 to filter out all entries equal 2010 and display onl those records.

On my form, I have combobox being populated with each unique year (from a different table). So my combobox values are 2010 and 2011.

Is it possible, when I select say 2011, I trim the right 4 characters and use as my Like criteria to refresh and requery the form, all done within VBA?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can refer to the value of a control in a query run from within an Access session, as long as the form which contains that control is open.

SELECT *
FROM YourTable
WHERE date_field_as_text Like "*" & Forms!YourForm!YourCombo;

So perhaps you can use a similar query as your form's record source, and do Me.Requery in the combo box's after update event.

If that's not close enough to what you want, please give us more information about the data types of the fields involved. Adding brief samples of the table data to your question could also help; please make it clear whether the "date" fields are text or Date/Time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...