Query Question - Can you help me fix a query that returns the wrong results?

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Hi Everyone,

Can you help me fix a query that returns the wrong results?

The query does execute but it returns the wrong results. My form has a single text box where the user enters a value. This value may be a customer ID, or it could be a last name or even a phone number. I would like to construct a query so that it would return results if the value in the text box matches either a customer ID, or a last name or a phone number in the Access database.

Here is what I tried so far.

VB.NET:
        strSQL = "Select FirstName + ' ' + LastName AS [Full Name], ID, " & _
                        "Format(PhoneCell, ""(###) 000-0000"") As [Cell Phone], " & _
                        "Format(PhoneHome, ""(###) 000-0000"") As [Home Phone], " & _
                        "Format(PhoneWork, ""(###) 000-0000"") As [Work Phone] " & _
                   "From Customers " & _
                  "Where ID Like ? " & _
                    "Or LastName Like ? " & _
                    "Or PhoneCell Like ? " & _
                    "Or PhoneHome Like ? " & _
                    "Or PhoneCell Like ? " & _
                  "Order By 1 "

The query returns extra not needed rows because some of those rows don't have a cell phone or a work phone. I think I need to add something extra to the "Or" keywords in rounded brackets but I'm not sure how to go about this the correct way.

Thanks.

Truly,
Emad
 
When you say that it's numeric, is it actually a number or is it text containing digits, because they are very different. Basically, you can't use LIKE with numbers.
 
Back
Top