G
Guest
Hi, I'm trying to develop a search function for my form, and found a similar
code for the website. After changing it, I've almost made the search work but
the problem I have right now is that the pop up function does not
differentiate between a correct ID and an incorrect ID. I think it has to do
with my If.. Else code. It will not do the 2 tasks in sequences. Below is my
code.
rivate Sub Search_Click()
Dim strPatient_ID As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![IDsearch]) Or (Me![IDsearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![IDsearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("Patient ID")
DoCmd.FindRecord Me!IDsearch
Patient_ID.SetFocus
strPatientID = Patient_ID.Text
IDsearch.SetFocus
strSearch = IDsearch.Text
'If matching record found sets focus in strPatientID
'and clears search control
If strPatient_ID <> strSearch Then
MsgBox "Match Found: " & strSearch & "" _
, , "Congratulations!"
IDsearch.SetFocus
IDsearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again." _
, , "Invalid Search Criterion!"
IDsearch.SetFocus
End If
End Sub
The problem starts at the Comment "If matching record found sets focus in
strPatientID 'and clears search control". The If Else function doesnt work.
In this set up, it'll going do the "If" task regardless if I type in an
existing ID or not.
Can anyone tell me what I wrote wrong? Thank you very much
code for the website. After changing it, I've almost made the search work but
the problem I have right now is that the pop up function does not
differentiate between a correct ID and an incorrect ID. I think it has to do
with my If.. Else code. It will not do the 2 tasks in sequences. Below is my
code.
rivate Sub Search_Click()
Dim strPatient_ID As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![IDsearch]) Or (Me![IDsearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![IDsearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("Patient ID")
DoCmd.FindRecord Me!IDsearch
Patient_ID.SetFocus
strPatientID = Patient_ID.Text
IDsearch.SetFocus
strSearch = IDsearch.Text
'If matching record found sets focus in strPatientID
'and clears search control
If strPatient_ID <> strSearch Then
MsgBox "Match Found: " & strSearch & "" _
, , "Congratulations!"
IDsearch.SetFocus
IDsearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again." _
, , "Invalid Search Criterion!"
IDsearch.SetFocus
End If
End Sub
The problem starts at the Comment "If matching record found sets focus in
strPatientID 'and clears search control". The If Else function doesnt work.
In this set up, it'll going do the "If" task regardless if I type in an
existing ID or not.
Can anyone tell me what I wrote wrong? Thank you very much