Home > Back-end >  Search an MS Access form for a record based on partial text
Search an MS Access form for a record based on partial text

Time:02-23

When creating a combo box with the form wizard, you can make it select a form record based on the combo box selection. I want to do a similar thing from a text box, but I want it to search for a partial string. I adjusted the form wizard code like this:

Private Sub txtSearchString_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[RequestName] LIKE *" & Str(Nz(Me![txtSearchString], 0)) & "*"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

I get a "Type mismatch" error. Is there something wrong with my code or is this something the FindFirst function isn't capable of?

CodePudding user response:

Try the following

   Dim rs As Object
   Set rs = Me.Recordset.Clone
   rs.FindFirst "[RequestName] LIKE '*" & Me.txtSearchString & "*'"
   If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  • Related