Danishdjinn
Danishdjinn

Reputation: 607

Seach function in Access syntax error: missing a comma in query expression

I have a problem while I'm working on a search function at Windows Access that allowed me to search after 3 things. In this case, it's first name, Last name and CPR. Now the CPR means it's a serial of unique numbers to each users on my Database.

It started as a macro then I changed it into VBA code because I want it to have the option to search after 3.

when it's in macro, it can only find 2 things because the limit for write characters in macro is 255, which is the reason that I changed it to VBA code which the characters limit should be unlimited.

Ah, I almost forgot, the code's in danish, but I think the basic functions of the code is almost pretty much same everywhere so...

Here is the problem:

On Error GoTo SøgEfterFornavn_Err

    If (IsNull(Forms!Navigationsformular!NavigationUnderformular!SearchFor)) Then
        Beep
        Exit Function
    Else
        DoCmd.SetFilter "Søgnings forespørgelse", "[Fornavn] Like ""*"" & [Forms]![Navigationsformular]![NavigationUnderformular]![SearchFor] & ""*"" Or [CPR] Like ""*"" & [Forms]![Navigationsformular]![NavigationUnderformular]![SearchFor] & ""*"" Or [Efternavn] Like ""*"" & [Formularer]![Navigationsformular]![NavigationUnderformular]![SearchFor] & ""*"", """"
        Exit Function
    End If


SøgEfterFornavn_Exit:
    Exit Function

SøgEfterFornavn_Err:
    MsgBox Error$
    Resume SøgEfterFornavn_Exit

It keeps saying that "Syntax error: missing a comma in query expression" which I don't understand? Did I do something wrong or?

Upvotes: 0

Views: 134

Answers (1)

agold
agold

Reputation: 6276

You have forgotten to put some quote signs ("):

DoCmd.SetFilter "Søgnings forespørgelse", "[Fornavn] Like ""*""" & [Forms]![Navigationsformular]![NavigationUnderformular]![SearchFor] & """*"" Or [CPR] Like ""*""" & [Forms]![Navigationsformular]![NavigationUnderformular]![SearchFor] & """*"" Or [Efternavn] Like ""*""" & [Formularer]![Navigationsformular]![NavigationUnderformular]![SearchFor] & ""*""", """"

You probably forgot them because you need to put the quote character twice to have it in the string (as escape character).

Upvotes: 1

Related Questions