469,950 Members | 2,171 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Select All if Textbox Empty


I have a form with text/combo boxes that draws from a query and sends records to a report.

The query has the following code in the criteria block of some of the columns:

This code tells the query to select only those records that match what was entered or selected in the pertinent text/combo box in the "report" form. So the SQL appears as follows:
SELECT tbl.fld1, tbl1.fld2, tbl1.fld3, tbl1.fld4
FROM tbl1
WHERE (((tbl1.fld1)=[Forms]![frmName]![fld1]) AND ((tbl1.fld2)=[Forms]![frmName]![fld2]))

So when I hit the report button. Only those records matching the search criteria set in the form appear in the report.

Sometimes I want to search by fld1 & fld2, and sometimes I want to search only by fld1 or only by fld2. Thus I leave the other tbo/cbo blank.

The problem with that is Access responds to the empty cbo/tbo as "Select all where fld is empty" rather than how I want it to - "Select All since cbo/tbo is empty".

Is there an if (or other) statement I can write into the query to tell it that if it comes across an empty tbo/cbo, "Select All" in that column?
Dec 3 '07 #1
1 2892
12,516 Expert Mod 8TB
Use the Like operator. Don't forget the wildcards. And if you want the Nulls, don't forget to Nz() the field first.
Dec 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Newbie | last post: by
reply views Thread by Tetet B via .NET 247 | last post: by
5 posts views Thread by Yuelin | last post: by
3 posts views Thread by Phillip Vong | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.