Find record by using Recordset.FindFirst : Recordset Find « Access « VBA / Excel / Access / Word






Find record by using Recordset.FindFirst

 
Sub findrecorder()
    Dim dbNorthwind As DAO.Database
    Dim dbPath As String
    DbPath = CurrentProject.Path & "mydb.mdb"
    Set dbNorthwind = OpenDatabase(dbPath)
    
    Dim rsEmployees As DAO.Recordset
    Dim rsCustomers As DAO.Recordset
    Set rsEmployees = dbNorthwind.OpenRecordset("Employees", dbOpenTable)
    Set rsCustomers = dbNorthwind.OpenRecordset("Customers", dbOpenTable)
    rsCustomers.MoveLast
    numCustomers = rsCustomers.RecordCount
    With rsEmployees
        .FindFirst "City = 'Seattle'"
        If .NoMatch Then
            MsgBox ("No Records Found!")
            .MoveFirst
        Else
            MsgBox ("Found "& .Fields(2).Value & " "& .Fields(1).Value & _
                 "in Seattle")
        End If
    End With
End Sub

 








Related examples in the same category

1.Finding the Record Position
2.Change column data case
3.Simple Select statement
4.SQL with where clause
5.Select specific column in select statement
6.Finding Records Using the Find Method
7.Finding a Record Based on Multiple Criteria
8.Finding a Specific Record in a Recordset
9.NoMatch property in Recordset