Three days trying to debug a very simple INSERT INTO statement

  • Thread starter Richard Hollenbeck
  • Start date
R

Richard Hollenbeck

I can't see anything wrong with the following StrSQL string but I get this
error:

Run-time error "3134':
Syntax error in INSERT INTO statement.

Here's the code:

Public Function myErrorHandler(Num As Long, descr As String, src As String)
As VbMsgBoxResult
Dim StrSQL As String
myErrorHandler = MsgBox("Error number: " & Num & vbCrLf & descr & vbCrLf
& "Source: " & src)

'report the error to the error log table
StrSQL = "INSERT INTO tblErrorLog (Number, Description, Source) VALUES
( " & Num & ", '" & descr & "', " & src & " )"
CurrentDb.Execute StrSQL, dbFailOnError
End Function

The debugger seems to be reading the Err.Number, Err.Description, and
Err.Source correctly, and I have carefully checked that the field names in
tblErrorLog are spelled correctly and are in the correct order. I'm calling
this function from within an error handler by saying:

Err_Form_Load:
Dim x
x = myErrorHandler(Err.Number, Err.Description, Err.Source)
Resume Err_Form_Load_Exit
End Sub

It correctly returns the msgBox with the error report inside it but hangs on
the syntax error in the query string.
 
G

Guest

Hi Richard,

It looks like the problem may be that you are missing single quotes around
the src variable, which is text. Try that and see if it works.

HTH, Ted Allen
 
R

Richard Hollenbeck

Yes, that was pretty much it. Thanks.

Ted Allen said:
Hi Richard,

It looks like the problem may be that you are missing single quotes around
the src variable, which is text. Try that and see if it works.

HTH, Ted Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top