i have a subform where the record source is a table. i have a button on the form that prompts the user to enter search criteria and then it finds that record. my problem is that i can't get it to continue searching for other records that match the entered criteria. so basically what i want to do is have a "find next" button similar to the one on the pop up box when you hit Ctrl-F in other applications.
This is the code behind the "Find" button that i already have:
Private Sub cmdFind_Click()
Dim db As Database
Dim rst As DAO.Recordset
Dim strCriteria As String
On Error GoTo err_frame
Set db = CurrentDb
Set rst = db.OpenRecordset("totaldata", dbOpenDynaset)
strCriteria = "[AccountTitle] Like '*" & InputBox("Enter the " _
& "first few letters of the Account to find" & "*'"
If strCriteria = "" Then
GoTo endsub
End If
rst.FindFirst strCriteria
frm.Bookmark = rst.Bookmark
If rst.NoMatch Then
MsgBox "No record found"
Else
Do Until rst.NoMatch
Debug.Print rst!AccountTitle
rst.FindNext strCriteria
Loop
End If
rst.Close
Set db = Nothing
Set rst = Nothing
Me.Refresh
Exit_frame:
Exit Sub
err_frame:
' MsgBox Err.Number
MsgBox Err.Description
Resume Exit_frame
endsub:
End Sub
any help someone can give me would be greatly appreciated.
This is the code behind the "Find" button that i already have:
Private Sub cmdFind_Click()
Dim db As Database
Dim rst As DAO.Recordset
Dim strCriteria As String
On Error GoTo err_frame
Set db = CurrentDb
Set rst = db.OpenRecordset("totaldata", dbOpenDynaset)
strCriteria = "[AccountTitle] Like '*" & InputBox("Enter the " _
& "first few letters of the Account to find" & "*'"
If strCriteria = "" Then
GoTo endsub
End If
rst.FindFirst strCriteria
frm.Bookmark = rst.Bookmark
If rst.NoMatch Then
MsgBox "No record found"
Else
Do Until rst.NoMatch
Debug.Print rst!AccountTitle
rst.FindNext strCriteria
Loop
End If
rst.Close
Set db = Nothing
Set rst = Nothing
Me.Refresh
Exit_frame:
Exit Sub
err_frame:
' MsgBox Err.Number
MsgBox Err.Description
Resume Exit_frame
endsub:
End Sub
any help someone can give me would be greatly appreciated.