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

Posted on 2003-02-18
Medium Priority
Last Modified: 2010-05-01
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
Question by:kennyD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 39

Accepted Solution

appari earned 150 total points
ID: 7979692

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) & "';")

Expert Comment

by:Sashi Rachabattula
ID: 7979832
if  "State" is a variable than u have to write what u did
else if "State" is a column name do what appari wrote  

Author Comment

ID: 7985550
Still didn't get it to work is there another way

Expert Comment

ID: 7985600
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.

Author Comment

ID: 7990836
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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question