0

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
1
  • Is there any reason why you do not wish to select only matching records ordered randomly?
    – Fionnuala
    Oct 20, 2012 at 19:16

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.