Query By Form (No results when field on table = blank) (1 Viewer)

George10988

Registered User.
Local time
Today, 00:37
Joined
Apr 23, 2011
Messages
41
Hello I am trying to connect a database search form to a query I made. I have put in some code in the criteria sections of the fields that I want to search. Of course these fields are referenced to their respective text boxes and submit button. It works perfectly unless one of the fields with in the table that the query looks in is null. Here is the code I am using

Like (IIf(IsNull([Forms]![frmDatabaseSearch]![txtFather]),"*",[Forms]![frmDatabaseSearch]![txtFather]))

If the data entry person wants to search for a female named mary but leaves the father txt box blank and clicks search, my query will not show any results, not even the girl's name "mary." I figured out that the reason this was happening was because Mary has no father listed in her record. As soon as I added a father to her record whala! my query pulled her record out. I want my query to return all results if text boxes are left blank even if those respective fields on the table are blank also. Is there any way to do this?
 

Red17

Registered User.
Local time
Today, 15:37
Joined
Sep 1, 2010
Messages
25
Try this:

In the Field line of your query, change the field name

[txtFather]

to

Father: Nz([txtFather], "")

Then in the criteria line in your Father field, put the following:

Like (IIf(IsNull([Forms]![frmDatabaseSearch]![txtFather]),"",[Forms]![frmDatabaseSearch]![txtFather])) & "*"
 

George10988

Registered User.
Local time
Today, 00:37
Joined
Apr 23, 2011
Messages
41
Sorry for the late response.

Thanks a ton!
 

Users who are viewing this thread

Top Bottom