Error code 3075 (1 Viewer)

Jamster45

New member
Local time
Today, 13:39
Joined
Aug 15, 2018
Messages
7
Hi There,

I got an error on this code:


Code:
Public Sub logging(Activity As String, filterQ As String)
    CurrentDb.Execute "INSERT INTO activiteitenlog (gebruikersnaam,activiteit,stringq,windowsGebruikersnaam,windowsComputernaam) Values('" & TempVars("gebruikersnaam").Value & "', '" & Activity & "', '" & filterQ & "', '" & Environ("username") & "','" & Environ("computername") & "')"
End Sub

I placed this on a form:

Private Sub Form_Load()
globals.logging "form opened", Me.filter
End Sub

I got the error: 3075, syntax is missing (operator)

The error is in the me.filter/filterQ section because, whitout it works fine


can someone help me and explain what im doing wrong here?
 
Last edited by a moderator:

jdraw

Super Moderator
Staff member
Local time
Today, 16:39
Joined
Jan 23, 2006
Messages
15,393
Suggest you post a copy of the database if possible.

No idea what this means/represents
me.filter/filterQ
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:39
Joined
Aug 30, 2003
Messages
36,129
What is contained in the filter when it happens? Try this:

http://www.baldyweb.com/ImmediateWindow.htm

like

Debug.Print filterQ

and you could use a string variable for the whole SQL string and print it too.
 

MarkK

bit cruncher
Local time
Today, 13:39
Joined
Mar 17, 2004
Messages
8,186
I commonly recommend you use a QueryDef, and this is no exception. It's more verbose in code terms, but simpler to understand the SQL, easier to see where each parameter value is being assigned, and delimiters are not your problem.
Consider code like...
Code:
Public Sub logging(Activity As String, filterQ As String)
    Const SQL_INSERT As String = _
        "INSERT INTO activiteitenlog " & _
            "( gebruikersnaam, activiteit, stringq, windowsGebruike, windowsComputernaam ) " & _
        "VALUES " & _
            "( p0, p1, p2, p3, p4 ) "
            
    With CurrentDb.CreateQueryDef("", SQL_INSERT)
        .Parameters(0) = TempVars("gebruikersnaam")
        .Parameters(1) = Activity
        .Parameters(2) = filterQ
        .Parameters(3) = Environ("username")
        .Parameters(4) = Environ("computername")
        .Execute dbFailOnError
        .Close
    End With

End Sub
Just my 2c...
Mark
 

JHB

Have been here a while
Local time
Today, 22:39
Joined
Jun 17, 2012
Messages
7,732
I don't know if it is a typo, but there is a space:
CurrentDb.Execute "INSERT INTO activiteitenlog (gebruikersnaam,activiteit,stringq,windowsGebruike rsnaam,windowsComputernaam) " _
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:39
Joined
Aug 30, 2003
Messages
36,129
I don't know if it is a typo, but there is a space:

There is no space, the forum adds one if there are too many characters in a row with no space. I added code tags to the OP's post, which will preserve the actual text.
 

JHB

Have been here a while
Local time
Today, 22:39
Joined
Jun 17, 2012
Messages
7,732
There is no space, the forum adds one if there are too many characters in a row with no space. I added code tags to the OP's post, which will preserve the actual text.
Okay - did you edit something in OP post or was adding code tags enough for the space to disappear?
How many characters are to many?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:39
Joined
Aug 30, 2003
Messages
36,129
All I did was add code tags; there was no space in the text. If memory serves, it's around 50. I'll test:

12345678901234567890123456789012345678901234567890123456789012345678901234567890

Edit: Looks like 60. There are no spaces in the numbers above.

Edit 2: it moved to 50!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:39
Joined
Feb 28, 2001
Messages
27,257
The SQL string doesn't have a closing semi-colon, which would make the SQL processor think that something else must be coming after your Environ("Computername") element. That something would normally be either the closing ";" or a delimiter for another argument or an operator for you to modify the last argument. I guess it picked "operator" to complain about even though you have a closing parenthesis after the last element of the VALUES clause.

It is either that or the "Activity" or "FilterQ" argument that were your inputs contained some form of punctuation that messed with the quote count. Remember that your string gets processed TWICE. Once by the VBA code as it is building that string. Once by the SQL query processor. Even if the string can be built by VBA, that doesn't mean that SQL is going to like it. (Which I'm guessing it does not.)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:39
Joined
Aug 30, 2003
Messages
36,129
I believe the semicolon is optional in Access Doc. I never include one when building SQL in VBA.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:39
Joined
Feb 28, 2001
Messages
27,257
Paul, I used to think it was, too, but I've tripped over it a few times. Admittedly rare, and being the yutz that I sometimes can be, I NEVER remember to take notes when it happens because I'm so focused on getting the darned thing running.
 

Users who are viewing this thread

Top Bottom