Public Sub DoSomething()
On Error GoTo ErrHandler
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim i As Integer
'Define using current database, and open table
Set db = CurrentDb
Set rst = db.OpenRecordset("yourtablename", dbOpenSnapshot)
'Make sure table has records, and set to first record.
With rst
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
End If
End With
'Loop through each record
With rst
For i = 1 To rst.RecordCount ' 1 to Count of records
If .Field5 = "xxx" Then
'do whatever
End If
'Move to the next record
.MoveNext
Next
End With
ExitHere:
'Clear variables used from memory
Set rst = Nothing
Set db = Nothing
i = 0
Exit Sub
ErrHandler:
'Always include error trapping. this is the bare minimum...
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Sub