garywood84
Registered User.
- Local time
- Today, 23:11
- Joined
- Apr 12, 2006
- Messages
- 168
I have a form with code behind it to generate a query in SQL. The generated SQL is like this:
SELECT * FROM bqryVolunteers WHERE bqryVolunteers.[Organisation] Like '*' AND bqryVolunteers.[Town/City] Like '*' AND bqryVolunteers.[County] Like '*';
This works fine, but only if NONE of the fields (Organisation, Town/City, County) contains a blank field. If there are blanks, then the query returns no records.
I managed to get around this by modifying the code so that the SQL string generated has WHERE bqryVolunteers.[Organisation] Like '*' or "". However, this doesn't work satisfactorily because when I then have a criteria for a field, I still get all the records returned, i.e.:
SELECT * FROM bqryVolunteers WHERE bqryVolunteers.Organisation] = "AnyCompany" AND bqryVolunteers.[Town/City] Like '*' or "" AND bqryVolunteers/[County] Like '"' or "";
returns all the records as if no Organisation had been specified.
Please can someone advise me how I can make this work correctly (i.e. in the case of this example, I should see records for all volunteers from "AnyCompany" regardless of what town/city or county they are from, even if they are blank.
Thanks in advance,
Gary
SELECT * FROM bqryVolunteers WHERE bqryVolunteers.[Organisation] Like '*' AND bqryVolunteers.[Town/City] Like '*' AND bqryVolunteers.[County] Like '*';
This works fine, but only if NONE of the fields (Organisation, Town/City, County) contains a blank field. If there are blanks, then the query returns no records.
I managed to get around this by modifying the code so that the SQL string generated has WHERE bqryVolunteers.[Organisation] Like '*' or "". However, this doesn't work satisfactorily because when I then have a criteria for a field, I still get all the records returned, i.e.:
SELECT * FROM bqryVolunteers WHERE bqryVolunteers.Organisation] = "AnyCompany" AND bqryVolunteers.[Town/City] Like '*' or "" AND bqryVolunteers/[County] Like '"' or "";
returns all the records as if no Organisation had been specified.
Please can someone advise me how I can make this work correctly (i.e. in the case of this example, I should see records for all volunteers from "AnyCompany" regardless of what town/city or county they are from, even if they are blank.
Thanks in advance,
Gary