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

Multi field search criteria problem

Status
Not open for further replies.

itchyII

MIS
Apr 10, 2001
167
Hi All,
This is a little long winded but this problem has had me stumped for weeks!
I have a problem concerning multiple criteria in a query. I have a search form that has 3 unbound text boxes. The form also has a subform that is tied to a query. Each text box on the form is tied to a specific field in the query. (e.g textbox1 searches in the strName field, textbox2 searches in the strCompany field, etc.) When a user enters some text in the text box, they then click a button that requeries the subform displaying the records where the text is found in the corresponding field. If only one text box has search criteria entered then the search is performed only on that field, if two text boxes have criteria entered then an “And” search is performed on both fields. I am using the following in the criteria field in my query:

Like “*|Forms![frmDataSearch]![strCriteria1]|*” & “*”

I place a statement similar to this in all of the three fields that I wish to search on. Here is the problem, all 3 fields in the underlying table must have data in them in order for all records to appear. If just one of the fields is null (or “”), the entire record is filtered out of the query. Here is an example:

Record in table:
strName: Bob
strCompany: “”
strRegion: North America

Text box craters
textbox1(search in Name): bob
textbox2(search in Company):
textbox3(search in Region):

This actually returns no records because the strCompany field in the underlying table is empty. What I basically want is that if no criteria is specified in any textbox then show all records, even those where the search fields may be empty strings. If only one of the textboxes has criteria specified, then show all records where that field is similar to the criteria, including those where either of the other two fields may contain empty strings, an so on…
I have tried adding to the search criteria in the query an “Or” condition, but this doesn’t work:
Criteria in query: Like “*|Forms![frmDataSearch]![strCriteria1]|*” & “*” Or “*”
I have tried creating a function to assess the value of the textbox and return one of two possible criteria strings but this also doesn’t work:
Criteria in query: Criteria(Forms![frmDataSearch]![strCriteria1])
It seems that no matter what I put in the criteria of the query, as soon as there is a criteria expression specified, it automatically filters out any records where this field is null or an empty string.

Any ideas?

ItchyII
 
I think the syntax should be:- Like Forms!frmDataSearch!strCriteria1 & "*" Or Forms!frmDataSearch!strCriteria1 Is Null
 
You wrote:
Like Forms!frmDataSearch!strCriteria1 & "*" Or Forms!frmDataSearch!strCriteria1 Is Null

This works fine if strCriteria1 is null but if it contains a value, it returns no records at all.
 

If you are searching for an occurance of the sciteria string anywhere in the column modify your query as follows.

Like "*" & Forms!frmDataSearch!strCriteria1 & "*" Or Forms!frmDataSearch!strCriteria1 Is Null Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
tlbroadbent....may I be so bold as to cut into this question. I am doing almost the exact same thing. I want the user to be able to type in... say Bob in the 1st field which would return record #1 and in the Company field type in XYZ Company (not Bob's Company), that would return record #2. So my result would be two or more different records that show all the Bob's in the Name field and all the XYZ Companies in the Company Field. My criteria on my query now says
Like "*" & [forms]![FormName]![FormControlName].[Value]& "*"

Any ideas why it's not working?

Thank you sooo much!
 

Cindi,

Your query should look something like the following.

Select <column list>
From Table
Where OwnerName Like &quot;*&quot; & [forms]![FormName]![CtrlName1] & &quot;*&quot;
Or CompanyName Like &quot;*&quot; & [forms]![FormName]![CtrlName2] & &quot;*&quot; Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
tlbroadbent,

That's what I have, doesn't work. I get all the records returned, not just the two I'm searching for. I have also posted this question in the Access General forum and Cosmo told me the same thing. There must be something else I'm doing wrong.

Thanks for your help, I don't really know where to go from here. Any suggestions?

Thanks,
Cindi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top