I have been trying the following code for a code to search for a record and display it in a textbox
Option Explicit
Dim conn As ADODB.Connection, rec1 As ADODB.Recordset
Dim esql1 As String
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rec1 = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\id\Project.mdb;Persist Security Info=False"
conn.Open
esql1 = "select * from table"
rec1.Open (esql1), conn, adOpenDynamic, adLockOptimistic
GetText
End Sub
Dim searchvar As Integer
Private Sub Command1_Click()
Text1 = ""
Text2 = ""
Text3 = ""
searchvar = InputBox("Enter item to find")
rec1.Close
rec1.Open ("select * from table where 'Key = searchvar'"), conn, adOpenStatic, adLockReadOnly
If rec1.Fields(0) <> "" Then
Text1 = rec1.Fields(1)
Text2 = rec1.Fields(2)
Text3 = rec1.Fields(3)
Else
MsgBox ("No matching records found")
rec1.Close
rec1.Open ("select * from table "), conn, adOpenDynamic, adLockOptimistic
GetText
End If
End Sub
Private Sub GetText()
If rec1.BOF = True Or rec1.EOF = True Then Exit Sub
Text1 = rec1.Fields(1)
Text2 = rec1.Fields(2)
Text3 = rec1.Fields(3)
End Sub
but the mathcing record is not getting displayed
please help