I have a table with three fields Fields(0,1,2) and i want to perform search using ADODC control in Visual Basic. The problem is that its possible for me to search in sequential order or when my recordset pointer is on that record. I just want to search records in a random manner. I am using MS Access(*.mdb) as my database and using ADODC for connection. Text7 contains search key.
Here is the Click event of search command button:
Private Sub Search_Click()
Dim flag As Integer
flag = 0
Do
If (Val(Text7.Text) = Adodc1.Recordset.Fields(0)) Then
flag = 1
Exit Do
ElseIf (Val(Text7.Text) <> Adodc1.Recordset.Fields(0) & Adodc1.Recordset.EOF = True) Then
flag = 0
Adodc1.Recordset.MoveFirst
Exit Do
End If
Adodc1.Recordset.MoveNext
Loop While Adodc1.Recordset.EOF = False
If (flag = 1) Then
Label1.Caption = Adodc1.Recordset.Fields(0) 'executed when record found
Label2.Caption = Adodc1.Recordset.Fields(1)
Label3.Caption = Adodc1.Recordset.Fields(2)
Else
x = MsgBox("Not Found")
End If
End Sub