Good Afternoon or morning wherever in the world you are.
I have a followup query about searching in forms. I have set up a basic search text box and assigned a button to search for company names.
Its going well but we are finding something that is annoying and slowing us down. The code we have used needs us to type the name of the company absolutely correct.
We would like to be able to type in even a few letters of this company or one or two words and search anmd it come back with a response.
The code I am using is below.
Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch 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 CompanyName1
DoCmd.ShowAllRecords
DoCmd.GoToControl ("CompanyName1")
DoCmd.FindRecord Me!txtSearch
CompanyName1.SetFocus
strStudentRef = CompanyName1.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in CompanyName1 and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
CompanyName1.SetFocus
txtSearch = ""
'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!"
txtSearch.SetFocus
End If
End Sub
Hope someone can help me. Im sure its very simple.
Thanks in advance
Cheers
Tones
I have a followup query about searching in forms. I have set up a basic search text box and assigned a button to search for company names.
Its going well but we are finding something that is annoying and slowing us down. The code we have used needs us to type the name of the company absolutely correct.
We would like to be able to type in even a few letters of this company or one or two words and search anmd it come back with a response.
The code I am using is below.
Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch 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 CompanyName1
DoCmd.ShowAllRecords
DoCmd.GoToControl ("CompanyName1")
DoCmd.FindRecord Me!txtSearch
CompanyName1.SetFocus
strStudentRef = CompanyName1.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in CompanyName1 and shows msgbox
'and clears search control
If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
CompanyName1.SetFocus
txtSearch = ""
'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!"
txtSearch.SetFocus
End If
End Sub
Hope someone can help me. Im sure its very simple.
Thanks in advance
Cheers
Tones