How do i search two field in a table using the SELECT command

The is the satement i a using in my code but does not work what am i doing wrong

Set rst = dbs.OpenRecordset("SELECT * FROM Table1 where " & State & " = '" & (txtbox1.Text) & "'" And City & " = '" & (txtbox2.Text) & "';")

I am trying to find the content of those two field in my table. I am using VB6
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Set rst = dbs.OpenRecordset("SELECT * FROM Table1 where " & State & " = '" & (txtbox1.Text) & "'" And City & " = '" & (txtbox2.Text) & "';")


Set rst = dbs.OpenRecordset("SELECT * FROM Table1 where State  = '" & (txtbox1.Text) & "' And City = '" & (txtbox2.Text) & "';")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sashi RachabattulaSCRUM Master, Technical ManagerCommented:
if  "State" is a variable than u have to write what u did
else if "State" is a column name do what appari wrote  
kennyDAuthor Commented:
Still didn't get it to work is there another way
Try troubleshooting your SQL statement in the VB Visual Data Manager. It's an add-in that shipped with VB5. I don't know if it's still included with VB6

I believe the criteria strings need to be in single quotes. I can't tell if they are in the above comments.
kennyDAuthor Commented:
Let me try and explain what I am trying to do. I have a table with several fields but I am only interested in three first name, last name and weight. Now on my form I have three test box label First Name, Last Name and Weight. What I am trying to accomplish is that if first name and last name textbox has a name that’s in the table then I would know what the weight of that person is by quarrying the weight field in the table.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.