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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionally returning all records for fields which can be null

Status
Not open for further replies.

postermmxvicom

Programmer
Jun 25, 2007
114
US
I want to have a query that returns all records when nothing is specified for the criteria. The field the criteria is in may or may not have data.

All of the expressions I have tried only return any record for records where the field exists - leaving out ones where the field is null.

Now, obviously, I can set the criteria to Is Null to return all records where the field is null. However, I am having trouble forming an expression for the criteria which:

1) returns only records where the field matches the given number, when a number is given

and

2) returns all records, including those with null values, when no number is given

Here is some examples of what I have tried, some don't work, others fail to work properly.

Code:
IIf(IsNull([Forms]![LotByMaterialSecondaryAndForm]![FKSecondary]),Like "*" Or Is Null,[Forms]![LotByMaterialSecondaryAndForm]![FKSecondary])


Code:
Like IIf(IsNull([Forms]![LotByMaterialSecondaryAndForm]![FKSecondary]),"*",[Forms]![LotByMaterialSecondaryAndForm]![FKSecondary]) Or Like IIf(IsNull([Forms]![LotByMaterialSecondaryAndForm]![FKSecondary]),Null,[Forms]![LotByMaterialSecondaryAndForm]![FKSecondary])


Code:
IIf(IsNull([Forms]![LotByMaterialSecondaryAndForm]![FKSecondary]),"",[Forms]![LotByMaterialSecondaryAndForm]![FKSecondary])

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Well, I think I got it now...so unless anybody sees a problem with this - pretend I was never here....

Code:
[Forms]![LotByMaterialSecondaryAndForm]![FKSecondary] OR [Forms]![LotByMaterialSecondaryAndForm]![FKSecondary] Is Null

One last thing: Sometimes I wonder; "Is that someone's signature? Or do they type that at the end of each post?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top