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

Problem with And/Or Condition in Query

Status
Not open for further replies.

beachcomber

IS-IT--Management
Jun 28, 2002
28
US
Hi,

I'm having a problem with my query below. Basically,
I have 3 user entered parameters that I'm trying to work
into the query. The second and third parameters are an or condition. For some reason, this query keeps returning all records in the system. Does anyone see anything I'm doing wrong?

"Select * From Customers where Customers.LastName Like " & "'%" & txtLastName & "%'" & "and Customers.FirstName like " & "'%" & txtFirstName & "%'" & "or Customers.Address1 like " & "'%" & txtAddress1 & "%'"

Thanks,
Beachcomber
 
You need to enclose the 2nd two parameters in pharens, otherwise the OR gets evaluated separately and is not tied to the second parm.

"Select * From Customers where Customers.LastName Like " & "'%" & txtLastName & "%'" & "and (Customers.FirstName like " & "'%" & txtFirstName & "%'" & "or Customers.Address1 like " & "'%" & txtAddress1 & "%')"
 
I had tried parens earlier but not as you had them
Your way was correct.

Thanks very much,
Beachcomber
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top