VBA code for query criteria

P

pompeyjim

I need to run a query from code and I want the query to get its criteria from
an item the user chooses in a drop down box. Ordinarily I would put the
criteria straight into the query like this [Please choose the Application
number] and of course the user would type in the Application number they
wanted, but I want the user to be able to pick the application number from
the drop down box. Can anyone tell me what the code for this would be?
 
J

Jeff Boyce

One approach to handling this is to use a form and a combobox (drop-down
box). Then modify your query to use that value (the combobox's) as the
parameter/criterion. The query's Criterion "cell" would look something
like:
Forms!YourForm!cboYourComboBox
Of course, the form would have to be open for this query to work. And you
could add a command button that ran that query on the form...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 
A

Al Campagna

popmpey,
Refer to the combo value on the form in your query.
While the form is open, a query criteria against a field of....
= Forms!frmYourFormName!cboMyComboName
will filter that query just like your "parameter" example.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top