I have a database that backs up a bunch of tables from our live oracle database and runs every night via a windows schedule task. I've had ongoing problems with it working some nights and not other nights, so I've decided I need to put some code into it to copy whatever errors are happening and putting them into a table. tblErrors contains 2 fields - Time and Error. When an error occurs, this code runs:
This code runs just fine when put it outside of my error trapping (i.e. error num is 0 and there's no error description). However, I can't get it to work with a real error.
I purposely created an error on this line of code:
Because the query is actually spelled qryBackup3yrAssets.
As a result, visual basic gives me an error on the line of code that appends the error record to the table. The error message that pops up says:
Run-time error '3075':
Syntax error (missing operator) in query expression ''Error number 7874: Microsoft Access can't find the object 'qryBacup3yrAssets.'');'
I think it might be having problems because of the fact that the error description string contains some single quotes, which the INSERT INTO statement is having a hard time interpretting. But, I have no idea how to fix this, since it seems like some error messages will have single quotes and some won't.
Anyone know what's going on or how to fix this?
Thanks!
Code:
DoCmd.RunSQL "INSERT INTO tblErrors VALUES ('" & Now() & "', '" _
& "Error number " & Err.Number & ": " & Err.Description & "');"
This code runs just fine when put it outside of my error trapping (i.e. error num is 0 and there's no error description). However, I can't get it to work with a real error.
I purposely created an error on this line of code:
Code:
DoCmd.OpenQuery "qryBacup3yrAssets"
Because the query is actually spelled qryBackup3yrAssets.
As a result, visual basic gives me an error on the line of code that appends the error record to the table. The error message that pops up says:
Run-time error '3075':
Syntax error (missing operator) in query expression ''Error number 7874: Microsoft Access can't find the object 'qryBacup3yrAssets.'');'
I think it might be having problems because of the fact that the error description string contains some single quotes, which the INSERT INTO statement is having a hard time interpretting. But, I have no idea how to fix this, since it seems like some error messages will have single quotes and some won't.
Anyone know what's going on or how to fix this?
Thanks!