Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53

    Unanswered: Using wildcards in Form Filter

    I'm trying to open a form and filter the records. However rather than finding all the records that MATCH the search string, I want all the records that CONTAIN the search string. So the obvious thing would be to add an * before and after it. The msgbox proves that that bit is ok.

    So if I enter "chair" I expect to get - "chairs", "table and chairs" etc.

    But that's where it goes pear shape. Here is my code which is for the button on the first form which has a textbox.


    Private Sub CommandProceed_Click()
    Dim SearchString As String
    SearchString = "*" & Me.TextboxEntry.Value & "*"
    MsgBox SearchString
    DoCmd.OpenForm "Customs Codes Lookup 2", , , "Description like " & SearchString, acFormReadOnly
    End Sub

    I get the error message "Syntax error (missing operator) in query expression 'Description like *chair*'.
    Thank you,
    James

  2. #2
    Join Date
    Jan 2003
    Posts
    56
    I had a similar problem - I wanted the user to be able to write any part of a company name and to have all matching records appear. I used the following line of code and it worked fine:


    stLinkCriteria = "[Company_Name]LIKE " & "'" & "*" & Me![txtCriteria] & "*" & "'"


    Hope this helps!

    C.

  3. #3
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53
    That works beautifully - I'd never have got there myself - many thanks.
    Thank you,
    James

  4. #4
    Join Date
    May 2013
    Posts
    1

    complete

    James ,
    Do you have complete code. ? I would like to use it for my database ? I am not sure where to place this ? I am new to vba
    stLinkCriteria = "[Company_Name]LIKE " & "'" & "*" & Me![txtCriteria] & "*" & "'"
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •