I have a cmd search function that searches my form for a specified Serial Number. See below:-
The problem is I have more than one asset with the same serial number, and the search only keeps finding the first record.
When the search finds the first asset is there a way to have another box to "Find Next" like in MS word so it continues to search the form for the next asset with that serial number?
Private Sub cmdSearch_Click()
Dim SerialNumberRef As String
Dim Search As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtsearch]) Or (Me![txtsearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtsearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in SerialNumber
DoCmd.GoToControl ("SerialNumber")
DoCmd.FindRecord Me!txtsearch
SerialNumber.SetFocus
SerialNumberRef = SerialNumber.Text
txtsearch.SetFocus
Search = txtsearch.Text
'If matching record found sets focus in SerialNumber and shows msgbox
'and clears search control
If SerialNumberRef = Search Then
MsgBox "Match Found For: " & Search, , "Congratulations!"
SerialNumber.SetFocus
txtsearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtsearch.SetFocus
End If
End Sub
Regards
Ezz
The problem is I have more than one asset with the same serial number, and the search only keeps finding the first record.
When the search finds the first asset is there a way to have another box to "Find Next" like in MS word so it continues to search the form for the next asset with that serial number?
Private Sub cmdSearch_Click()
Dim SerialNumberRef As String
Dim Search As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtsearch]) Or (Me![txtsearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtsearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in SerialNumber
DoCmd.GoToControl ("SerialNumber")
DoCmd.FindRecord Me!txtsearch
SerialNumber.SetFocus
SerialNumberRef = SerialNumber.Text
txtsearch.SetFocus
Search = txtsearch.Text
'If matching record found sets focus in SerialNumber and shows msgbox
'and clears search control
If SerialNumberRef = Search Then
MsgBox "Match Found For: " & Search, , "Congratulations!"
SerialNumber.SetFocus
txtsearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtsearch.SetFocus
End If
End Sub
Regards
Ezz