Hi guys, 
I downloaded a sample of how to search for text in MS Access using a query.
My problem now is that I can find the record only if I write the complete name of the employee, but let`s suppose that I would like to find them just by the first name/surname, or part of it and all this data is stored in the same field.
I have the code here, if you could help me with a suggestion for this...I will be very glad. tks.
I downloaded a sample of how to search for text in MS Access using a query.
My problem now is that I can find the record only if I write the complete name of the employee, but let`s suppose that I would like to find them just by the first name/surname, or part of it and all this data is stored in the same field.
I have the code here, if you could help me with a suggestion for this...I will be very glad. tks.
Code:
[LEFT]Private Sub cmdSearch_Click()
Dim strStudentRef As String
Dim strSearch As String[/LEFT]
[LEFT]'Check txtSearch for Null value or Nill Entry first.[/LEFT]
[LEFT] If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'---------------------------------------------------------------[/LEFT]
[LEFT]'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID[/LEFT]
[LEFT] DoCmd.ShowAllRecords
DoCmd.GoToControl ("strStudentID")
DoCmd.FindRecord Me!txtSearch[/LEFT]
[LEFT] strStudentID.SetFocus
strStudentRef = strStudentID.Text
txtSearch.SetFocus
strSearch = txtSearch.Text[/LEFT]
[LEFT]'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control[/LEFT]
[LEFT] If strStudentRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
strStudentID.SetFocus
txtSearch = ""[/LEFT]
[LEFT] '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[/LEFT]