Generic Criteria

N

nybaseball22

Is there a criteria I can enter in a query field that will return
records based on a selection from a combo box if it is made, or will
return all records if there is no selection made?

Thanks
 
G

Guest

It might have helped if we had some table/field names or SQL...

SELECT ....
FROM ....
WHERE [FieldName] = Forms!frmA!cboYourCombo or Forms!frmA!cboYourCombo Is
Null;
 
G

Guest

In SQL it will look like:

Select * From TableName
Where FieldName = Forms![FormName]![ComboName] Or
Forms![FormName]![ComboName] Is Null

**************************************
In query design, under the field you want to filter on write
Forms![FormName]![ComboName]
To refer to the combo

Then create another field in the query with
Forms![FormName]![ComboName]

And under it write the criteria:

Is Null

So if the combo is left empty all the records will be returned
 
N

nybaseball22

I was trying to keep it generic because it would apply to many queries
in my database. I am trying to create it in design view because I am
not very good with SQL. I can try SQL if that is easier, though.

Below is an example of one of my queries. I have 4 of these that
filter the information for 4 different fields. Trying to get it all
into one.

Thanks again.

SELECT ExpensesMain.[Date of Expense], ExpensesMain.[Expense Type],
ExpensesMain.Amount, ExpensesMain.Mileage, ExpensesMain.Vendor,
ExpensesMain.[Charge Code], ExpensesMain.Reason,
ExpensesMain.Comments, ExpensesMain.[Report Date],
ExpensesMain.Receipt, ExpensesMain.[Submitted to System], ExpensesMain.
[Charge Card]
FROM ExpensesMain
WHERE (((ExpensesMain.[Report Date])=[Forms]![ExpensesPopUp]!
[RptDate]))
ORDER BY ExpensesMain.[Date of Expense] DESC , ExpensesMain.[Expense
Type];
 

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