Hi
I am trying to put a simple search facility on my database without using a combo box/filter. I have got this far below, but this will only find 1 record and then won't search any futher.
Can anyone help me please??
Thanks
Louise
Private Sub Command156_Click()
Dim strnhsRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtsearch1]) Or (Me![txtsearch1]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtsearch1].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in strsearch (dob)
DoCmd.ShowAllRecords
DoCmd.GoToControl ("cmdnhsno")
DoCmd.FindRecord Me!txtsearch1
cmdnhsno.SetFocus
strnhsRef = cmdnhsno.Text
txtsearch1.SetFocus
strSearch = txtsearch1.Text
'If matching record found sets focus in strsearch (dob) and shows msgbox
'and clears search control
If strnhsRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
cmdnhsno.SetFocus
txtsearch1 = ""
Else
If strnhsRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
cmdnhsno.SetFocus
txtsearch1 = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Date of Birth Search or Create a New Record.", _
, "Invalid Search Criterion!"
txtsearch1.SetFocus
End If
End If
End Sub
I am trying to put a simple search facility on my database without using a combo box/filter. I have got this far below, but this will only find 1 record and then won't search any futher.
Can anyone help me please??
Thanks
Louise
Private Sub Command156_Click()
Dim strnhsRef As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtsearch1]) Or (Me![txtsearch1]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtsearch1].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in strsearch (dob)
DoCmd.ShowAllRecords
DoCmd.GoToControl ("cmdnhsno")
DoCmd.FindRecord Me!txtsearch1
cmdnhsno.SetFocus
strnhsRef = cmdnhsno.Text
txtsearch1.SetFocus
strSearch = txtsearch1.Text
'If matching record found sets focus in strsearch (dob) and shows msgbox
'and clears search control
If strnhsRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
cmdnhsno.SetFocus
txtsearch1 = ""
Else
If strnhsRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
cmdnhsno.SetFocus
txtsearch1 = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Date of Birth Search or Create a New Record.", _
, "Invalid Search Criterion!"
txtsearch1.SetFocus
End If
End If
End Sub