Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic filters on query

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I want to create a dynamic filter on a query I have. Is there a way to add a "where" statement to a query using VBA? I have a form and if the user selects "Show only zip code 92705" then I want to be able to add that condition to my sql statement. I tried just adding [Forms]![MyForm]![MyControl] to the criteria of the query, but sometimes the user won't need to sort by zip code, but by another field and if I leave this criteria in query, my query doesn't return anything. Any ideas? Thanks!!
 
Hi,

how about setting the criteria to =
Forms![MyForm]![ctl1] or Forms![MyForm]![ctl2] etc, that way, as long as there's criteria selection, the query won't go blank.

Tin Tin
 
I need to add something more.

If you'd like to return all records when the query is blank,
set like this:

ZipCode [EnterZipCode]
Is Null
[EnterZipCode] Is Not Null

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top