Help... I've been asked to do a VB6.0 program. I'm required to enter values in a database that will be queried later on. Unfortunately, I can't seem to get the code right.

This is what this part of the program should do:
1. Get the name to be searched
2. Take the entered name and compare it with the values in the database.
3. If the entered name is equivalent to a certain value in the database, it will then proceed to get other information (in this case, a field with a date) and put it on the list box...

Well, I don't seem to have explained that properly but I hope you can help me. The code might look really lame and the error is on the bold text so far.

Dim searchname

Private Sub cmdgo_Click()
searchname = txtsearchname.Text

Set mydb1 = OpenDatabase(App.Path & "\parlordb.mdb")
Set myrs1 = mydb1.OpenRecordset("parlordb")

[B]myrs1.Open ("select * from parlordb where custname=searchname")[/B]
Do Until myrs1.EOF
    lstdate.AddItem (myrs1!custdate)
    myrs1.MoveNext
Loop
myrs1.Close

End Sub

Thank you in advance!

Recommended Answers

All 5 Replies

Try:

("select * from parlordb where custname=" & searchname)

It appears you are using DAO as opposed to ODBC. If so, why not use:

myrs1.FindFirst txtsearchname.Text

Set mydb1 = OpenDatabase(App.Path & "\parlordb.mdb")
Set myrs1 = mydb1.OpenRecordset("parlordb")

myrs1.Open ("select * from parlordb where custname=searchname")

Your mistake is in your syntax. You have a variable inside a quotation mark.

myrs1.Open("Select * from parlordb where custname=" & searchname)

Private Sub show_Click()

ssql = "select name from info where id = 3"
Text1.Text = Val(ssql)
End Sub

Dim searchname

I think you need to write

Dim searchname as string

or you if not want to declare variable then can write

"select * from parlordb where custname ='" & text1.Text & "' "

for text/string datatype use single quote

"Select * From MyTable Where CustomerName = '" & searhname & "' "

for number datatype no single quote

"Select * From MyTable Where CustomerName = " & searhname & " "
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.