IIF Statement - How to specify NO CRITERIA

R

reddy

I have a query that obtains its critieria from a form.

Select *
From tblData
Where Date=[Forms]![FrmMonthlies]![CmbDate]

If no date is chosen on the Form, I want the Date criteria in the Query to
be blank.

I tried this:
Select *
From tblData
Where Date=
IIF([Forms]![FrmMonthlies]![CmbDate]="","",[Forms]![FrmMonthlies]![CmbDate])

This gives me an error. Please advise.
 
K

Klatuu

Where [Date] Like IIf(IsNull([Forms]![FrmMonthlies]![CmbDate], "*",
[Forms]![FrmMonthlies]![CmbDate])

Note the brackets around the field name Date
Date is a reserved word and should not be used as a name. It will cause
Access some confusion. Enclosing it in brackets will usually, but not
always, avoid the problems.
The best thing to do would be to change the name to something meaningful.
It not only avoid the use of a reserved word, but it gives you and anyone
else that may have to work on the application an idea of what it is used
for:
SaleDate EndDate BirthDate or whatever.
 
J

John W. Vinson

I have a query that obtains its critieria from a form.

Select *
From tblData
Where Date=[Forms]![FrmMonthlies]![CmbDate]

If no date is chosen on the Form, I want the Date criteria in the Query to
be blank.

Try

Select *
From tblData
Where [Date]=[Forms]![FrmMonthlies]![CmbDate]
OR [Forms]![FrmMonthlies]![CmbDate] IS NULL

Note that Date is a VERY BAD choice of fieldname, as it's a reserved word for
the builtin Date() function - Access *will* get confused.
 

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