Hi,
I'm having trouble with using a where statement linked to fields when the field is empty. I need a way to say if field is null then 'do nothing'/'select all' else use the text from the box.
I have a form (ServicesRCSSearch) which has 3 combo boxes (Location1, Location2 and Location3). These fields are linked to a query. The button on the form generates the query.
My SQL for the query is currently:
Select Services.Key, Services.Location, Services_1.Location, Services_2.Location
From Services, Services_1, Services_2 (copies of the same table all left joined)
Where
((IIf(forms!ServicesRCSSearch!Location1 Is Null,"",services.Location=forms!ServicesRCSSearch!Location1))<>False)
And ((Services_1.Location)=IIf(forms!ServicesRCSSearch!Location2 Is Null,forms!ServicesRCSSearch!Location1,forms!ServicesRCSSearch!Location2))
And ((Services_2.Location)=IIf(forms!ServicesRCSSearch!Location3 Is Null,forms!ServicesRCSSearch!Location1,forms!ServicesRCSSearch!Location3))
This works in that it uses the fields to filter the query but when Location1 is empty there are no results as you can see from the code.
I'd love some help, it's driving me nuts.
Thanks
I'm having trouble with using a where statement linked to fields when the field is empty. I need a way to say if field is null then 'do nothing'/'select all' else use the text from the box.
I have a form (ServicesRCSSearch) which has 3 combo boxes (Location1, Location2 and Location3). These fields are linked to a query. The button on the form generates the query.
My SQL for the query is currently:
Select Services.Key, Services.Location, Services_1.Location, Services_2.Location
From Services, Services_1, Services_2 (copies of the same table all left joined)
Where
((IIf(forms!ServicesRCSSearch!Location1 Is Null,"",services.Location=forms!ServicesRCSSearch!Location1))<>False)
And ((Services_1.Location)=IIf(forms!ServicesRCSSearch!Location2 Is Null,forms!ServicesRCSSearch!Location1,forms!ServicesRCSSearch!Location2))
And ((Services_2.Location)=IIf(forms!ServicesRCSSearch!Location3 Is Null,forms!ServicesRCSSearch!Location1,forms!ServicesRCSSearch!Location3))
This works in that it uses the fields to filter the query but when Location1 is empty there are no results as you can see from the code.
I'd love some help, it's driving me nuts.
Thanks