Hi Guys,
I'm new to all this so please bare with me if I miss anything or dont explain something clearly enough. I have a query with the code below.
Although the code works prefectly I'd like the search to include a wild card option i.e. add * before the reference query in the text box.
Does anybody have any ideas? Any help would be greatly appreciated.
RefID is the field being searched.
txtRefSeach is the text box the data is input.
cmdRefSearch is the button.
Private Sub cmdReqSearch_Click()
Dim strRefRef As String
Dim strRefSearch As String
'Check txtRefSearch for Null value or Nill Entry first.
If IsNull(Me![txtRefSearch]) Or (Me![txtRefSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtRefSearch].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtRefSearch
'and evaluates this against values in RMRefID
DoCmd.ShowAllRecords
DoCmd.GoToControl "RefID"
DoCmd.FindRecord Me!txtRefSearch
RefID.SetFocus
strRefRef = RefID.Text
txtRefSearch.SetFocus
strRefSearch = txtRefSearch.Text
'If matching record found sets focus in RMRefID and shows msgbox
'and clears search control
If strRefRef = strRefSearch Then
MsgBox "Reference Found For: " & strRefSearch, , "Success!"
RefID.SetFocus
txtRefSearch = ""
'If value not found sets focus back to txtRefSearch and shows msgbox
Else
MsgBox "Reference Not Found For: " & strRefSearch & " Please Try Again", _
, "Invalid Search Reference!"
txtRefSearch.SetFocus
End If
End Sub
I'm new to all this so please bare with me if I miss anything or dont explain something clearly enough. I have a query with the code below.
Although the code works prefectly I'd like the search to include a wild card option i.e. add * before the reference query in the text box.
Does anybody have any ideas? Any help would be greatly appreciated.
RefID is the field being searched.
txtRefSeach is the text box the data is input.
cmdRefSearch is the button.
Private Sub cmdReqSearch_Click()
Dim strRefRef As String
Dim strRefSearch As String
'Check txtRefSearch for Null value or Nill Entry first.
If IsNull(Me![txtRefSearch]) Or (Me![txtRefSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtRefSearch].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtRefSearch
'and evaluates this against values in RMRefID
DoCmd.ShowAllRecords
DoCmd.GoToControl "RefID"
DoCmd.FindRecord Me!txtRefSearch
RefID.SetFocus
strRefRef = RefID.Text
txtRefSearch.SetFocus
strRefSearch = txtRefSearch.Text
'If matching record found sets focus in RMRefID and shows msgbox
'and clears search control
If strRefRef = strRefSearch Then
MsgBox "Reference Found For: " & strRefSearch, , "Success!"
RefID.SetFocus
txtRefSearch = ""
'If value not found sets focus back to txtRefSearch and shows msgbox
Else
MsgBox "Reference Not Found For: " & strRefSearch & " Please Try Again", _
, "Invalid Search Reference!"
txtRefSearch.SetFocus
End If
End Sub