DoCmd.RunSQL Problem, please help!!!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sorry to trouble you guys with possible an easy question.

The issue I have is that I'm trying to write an error handler into a table.

What I had so far was;

DoCmd.RunSQL "INSERT INTO tblEventlog (EventDate, ErrorSource, " & _
"ErrorHandler) VALUES (Now(), 'Exec Summary', " & err.Description & ");"

It keeps throwing an error due to the err.Description. I have tried putting
the Err.Desciption into single quotes before closing the main SQL statement
off to get it too.

I've tried using a variable to manage this rather than the err.Description
and also build the SQL statement into a string (called strHandler) and then
had -

DoCmd.RunSQL strHandler

....but this also throws the same error. Any chances you could help at all
please??

Thanks in advance.

DaveO.
 
Hi Dave,

err.Description is a string, therefore needs quotes.
suggest a debug.print err.description instruction before your docmd
statement
in order to see what the string is.
What exactly is the error message you're getting?

Linda
 
The error message reads'

"Run-time error '3075': Syntax error (missing operator) in query expression
'Microsoft Access can't find the object 'qryExec_Summar.'"

Now I've deliberatly changed the name of the query so that it forces an
error so that we hit the error handler I'm trying to use. Just not sure why I
can't specify a variable in the DoCmd statement.

What would the bebug.print help with??

Thanks for your help!!
 
Hi,
Not sure where you're getting qryExec_Summar from,
it's not mentioned in your first post.

What I would suggest is going back to the method of putting your
sql string in a variable and printing the contents to the debug window
before trying to execute it.
That way, you get to see what the concatenated string looks like.
Usually the error is then quite obvious.
 
One thing i noticed was your now() needed to be outside your string inorder
to return the current date.

DoCmd.RunSQL "INSERT INTO tblEventlog (EventDate, ErrorSource, " & _
"ErrorHandler) VALUES (Now(), 'Exec Summary', " & err.Description & ");"

LIKE THIS:

DoCmd.RunSQL "INSERT INTO tblEventlog (EventDate, ErrorSource, " & _
"ErrorHandler) VALUES (" & Now() & ", 'Exec Summary', " & err.Description &
");"
 
Back
Top