DAO: In VB 6.0, how do i search a access database?
-
I am using the ADO in VB 6 and I was wondering how I could search the active database for a specific value. If someone could please give me a hand with this, that would be great!:)
Your question is a little decieving because you mention two different technologies used to access a database. I will assume you are using ADO. Here is an example to "search" a database. You will need to add a reference to the ADO object library in your program before running this code.
Dim conn As New ADODB.Connection
Dim adors As New ADODB.Recordset
Dim sql As Stringsql = "SELECT User_ID Where username = '" & replace(txtUserName.Text, "'", "''") & "'"
Set conn = New ADODB.Connection
Set adors = New ADODB.Recordsetconn.ConnectionString =
"[YourConnectionStringGoesHere]"
conn.Open
adors.ActiveConnection = conn
adors.Open (sql)
If Not adors.EOF Then
Do Until adors.EOF
MsgBox txtUserName.Text & "'s user id is " & adors("User_ID")
adors.MoveNext
Loop
Else
MsgBox "There are no records that match that name"
End Ifadors.Close
Set adors = Nothing
conn.Close
Set conn = NothingHTH Nick Parker
If the automobile had followed the same development as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year killing everyone inside. -Robert Cringely