Question : How to create a text search facility with wildcard

I am trying to use the example in the attached file for creating a simple text search facility in my database. However, I am searching for name and would like to be able to use wildcards in the code so that I don't have to type the whole name when searching.

Can anyone help

Answer : How to create a text search facility with wildcard

FindRecord is extremely limited, can be a massive performance hit, and you can't really customize it. You can kludge it, and use various combinations of macros and SendKeys, but it's a terrible workaround in my opinion and one sure to bite you later.

Try the code below in place of your current code. The only requirement is that you have a Reference set to the DAO libarary, but you've probably already got that anyway. The code uses the RecordSEtClone object, which is an exact copy of the current Form's recordset ... basically, if it finds a match via FindFirst, you can then set the Form's Bookmark to that of the RecordsetClone ...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
Private Sub cmdSearch_Click()
    Dim rst As DAO.Recordset
    
'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 strStudentID
Set rst = Me.RecordsetClone
rst.FindFirst "strStudentID LIKE '*" & Me.txtSearch & "*'"
 
If Not rst.NoMatch Then
  MsgBox "Match Found For: " & strSearch, , "Congratulations!"
  Me.Bookmark = rst.Bookmark
Else
 MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", , "Invalid Search Criterion!"
End If  
       
End Sub
Random Solutions  
 
programming4us programming4us