|
Question : Query based on multiple criteria
|
|
I'm trying to build a query based on a form with multiple fields (Agency Name, State, Last Name). The problem arises when I only enter information into one of the fields on the form.
For example, if I utilize all 3 fields, a contact matching all 3 criteria will be displayed however, if I opt to use only one field (lets say the Agency name), I get no reults.
Here is the code as it is now:
SELECT [Contact Information].LastName, [Contact Information].State, [Contact Information].State FROM [Contact Information] WHERE ((([Contact Information].LastName)=[Forms]![Main Switchboard]![Text3]) AND (([Contact Information].Agency)=[Forms]![Main Switchboard]![Text7]) AND (([Contact Information].State)=[Forms]![Main Switchboard]![Text11]));
|Any sugestions?
|
|
Answer : Query based on multiple criteria
|
|
do this instead:
SELECT [Contact Information].LastName, [Contact Information].State, [Contact Information].State FROM [Contact Information] WHERE ((([Contact Information].LastName) like nz([Forms]![Main Switchboard]![Text3]),*) AND (([Contact Information].Agency) like nz([Forms]![Main Switchboard]![Text7]),*) AND (([Contact Information].State) like nz([Forms]![Main Switchboard]![Text11]),*));
|
|
|
|