Hi All
I am trying to create a script that allows me to search a database for records that match 2 search criteria from different fields. In this case a patch panel number and a patch panel port number.
I can't get it to work. I get no errors, but i always get the result 'Match not found...'
Please help!
Many thanks in advance!
Here is the code:
'--------------------------------------------------------------
'Matthew Jones 28-01-07
'--------------------------------------------------------------
Private Sub cmdSearch2_Click()
Dim strsearchnumber2 As String
Dim strsearchnumber3 As String
Dim strSearch2 As String
Dim strSearch3 As String
'Check txtSearch2 for Null value or Nill Entry first.
If IsNull(Me![txtSearch2]) Or (Me![txtSearch2]) = "" Then
MsgBox "Please enter Patch Port Number!", vbOKOnly, "Invalid Search Critera!"
Me![txtSearch2].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Check txtSearch3 for Null value or Nill Entry first.
If IsNull(Me![txtSearch3]) Or (Me![txtSearch3]) = "" Then
MsgBox "Please enter a Patch Number!", vbOKOnly, "Invalid Search Critera!"
Me![txtSearch3].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch2 and txtSearch3
'and evaluates this against values in patchportnumber and patchnumber
DoCmd.ShowAllRecords
DoCmd.GoToControl ("patchportnumber")
DoCmd.FindRecord Me!txtSearch2
patchportnumber.SetFocus
strsearchnumber2 = patchportnumber.Text
txtSearch2.SetFocus
strSearch2 = txtSearch2.Text
DoCmd.ShowAllRecords
DoCmd.GoToControl ("patchnumber")
DoCmd.FindRecord Me!txtSearch3
patchnumber.SetFocus
strsearchnumber3 = patchnumber.Text
txtSearch3.SetFocus
strSearch2 = txtSearch3.Text
'If 1st matching field found checks 2nd field. If both match sets focus
'in patchportnumber and shows msgbox
'and clears search control
If strsearchnumber2 = strSearch2 Then
If strsearchnumber3 = strSearch3 Then
MsgBox "Match Found For: " & strSearch2, , "Patch Port Number Found"
patchportnumber.SetFocus
txtSearch2 = ""
txtSearch3 = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For 1: " & strSearch2 & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch2.SetFocus
End If
Else
MsgBox "Match Not Found For 2: " & strSearch3 & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch3.SetFocus
End If
End Sub
I am trying to create a script that allows me to search a database for records that match 2 search criteria from different fields. In this case a patch panel number and a patch panel port number.
I can't get it to work. I get no errors, but i always get the result 'Match not found...'
Please help!
Many thanks in advance!
Here is the code:
'--------------------------------------------------------------
'Matthew Jones 28-01-07
'--------------------------------------------------------------
Private Sub cmdSearch2_Click()
Dim strsearchnumber2 As String
Dim strsearchnumber3 As String
Dim strSearch2 As String
Dim strSearch3 As String
'Check txtSearch2 for Null value or Nill Entry first.
If IsNull(Me![txtSearch2]) Or (Me![txtSearch2]) = "" Then
MsgBox "Please enter Patch Port Number!", vbOKOnly, "Invalid Search Critera!"
Me![txtSearch2].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Check txtSearch3 for Null value or Nill Entry first.
If IsNull(Me![txtSearch3]) Or (Me![txtSearch3]) = "" Then
MsgBox "Please enter a Patch Number!", vbOKOnly, "Invalid Search Critera!"
Me![txtSearch3].SetFocus
Exit Sub
End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch2 and txtSearch3
'and evaluates this against values in patchportnumber and patchnumber
DoCmd.ShowAllRecords
DoCmd.GoToControl ("patchportnumber")
DoCmd.FindRecord Me!txtSearch2
patchportnumber.SetFocus
strsearchnumber2 = patchportnumber.Text
txtSearch2.SetFocus
strSearch2 = txtSearch2.Text
DoCmd.ShowAllRecords
DoCmd.GoToControl ("patchnumber")
DoCmd.FindRecord Me!txtSearch3
patchnumber.SetFocus
strsearchnumber3 = patchnumber.Text
txtSearch3.SetFocus
strSearch2 = txtSearch3.Text
'If 1st matching field found checks 2nd field. If both match sets focus
'in patchportnumber and shows msgbox
'and clears search control
If strsearchnumber2 = strSearch2 Then
If strsearchnumber3 = strSearch3 Then
MsgBox "Match Found For: " & strSearch2, , "Patch Port Number Found"
patchportnumber.SetFocus
txtSearch2 = ""
txtSearch3 = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For 1: " & strSearch2 & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch2.SetFocus
End If
Else
MsgBox "Match Not Found For 2: " & strSearch3 & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch3.SetFocus
End If
End Sub