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

Query problem

Status
Not open for further replies.

chrisgarvey

Technical User
Mar 27, 2003
64
0
0
GB
I have a table with 3 fields:

Field 1
Field 2
Field 3

I want to using a query search for a specific item in any of the above fields.

Is this possible?

Thank you for your time,

Chris Garvey
 
From query design view put your criteria for the first field in first row, the same criteria in the second row of the second field, and the same criteria in the third row of the third field. IN effect, you are saying to bring up all records where field1 = criteria OR field2 = criteria OR field3 = criteria. If you put the criteria in all on the same row, you are asking for records where field1 = criteria AND field2 = criteria AND field3 = criteria

The SQL will look something like this:
SELECT FIELD1, FIELD2, FIELD3
FROM TABLE1
WHERE (((TABLE1.FIELD1)=#1/1/2001#)) OR (((TABLE1.FIELD2)=#1/1/2001#)) OR (((TABLE1.FIELD3)=#1/1/2001#));

 
Yes its possible

several ways to do it though
an easy way is just to use the OR function in your statement
example

i have used the following with no problems

"Select * from MyAddBook Where TOWN like " & txt & " Or ADDRESS2 like " & txt & " Or COUNTY like " & txt & " Order by Surname,FirstName"

"txt" being the item you are searching for ie: data in textbox

hope this helps
 
oldwiseone, looks like we were posting about the same time. Don't forget to deliniate your text with single quotes:
"Select * from MyAddBook Where TOWN like '" & txt & "' Or ADDRESS2 like '" & txt & "' Or COUNTY like '" & txt & "' Order by Surname, FirstName"
 
Thank you all for your help!

I'm still having problems though.

Below is the SQL:

FROM photograph
WHERE (((photograph.Sold)=" False") AND ((photograph.Keyword1)=[enter keyword])) OR (((photograph.Keyword2)=[enter keyword])) OR (((photograph.Keyword3)=[enter keyword]));

This should do the following:
If keyword 1,2,3 = [enter keyword] AND sold = false.

But the False part does not work!

Any help would be much appreciated.

Chris
 
joyinok

Sorry for forgetting to show the (') in the example

in my programs I deliniate the string earlier in my code
like

txt = "'" & txt & "%'"

just thought I would clear that up.
 
Thank you all for your help.

Much appreciated.

Chris Garvey
 
chrisgarvey, you need to add the false criteria to each row of the OR criteria.
Right now, the false criteria is only applying to the first criteria
WHERE (((TABLE1.FIELD1)=#1/1/2002#) AND ((TABLE1.TRUEFALSEFIELD)="false")) OR (((TABLE1.FIELD2)=#1/1/2002#) AND ((TABLE1.TRUEFALSEFIELD)="false")) OR (((TABLE1.FIELD3)=#1/1/2002#) AND ((TABLE1.TRUEFALSEFIELD)="false"));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top