0

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!

6
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by jireh
0

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

0

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

Edited by abu taher: n/a

0

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 & " "
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.