none
dbFailOnError is not causing error handling code to execute

    Question

  • I am having trouble capturing the errors during a DAO recordset looping.

    I have a table of querynames that I loop through using each queryname in a db.execute. When there is a problem with one of the queries, my error handler code is never executed and I get the error message instead (despite using the dbFailonError setting ??). Here is the code with comments where the error happens:

    Private Function ITERATE_Query_Profile() Dim strSQL As String strSQL = "SELECT QueryName FROM tbl_QueryNames" Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)

    Dim db As Database Do Until rst.EOF Set db = CurrentDb On Error GoTo ErrorHandler db.Execute rst![QueryName], dbFailOnError '<==errors here on query's syntax (i have intentionally wrote bad sql in the query being run to cause this error) but does not go to ErrorHandler code and shows a msgbox error about the query's syntax Set db = Nothing rst.MoveNext Loop Exit Function Exit_ITERATE_Query_Profile: Set rst = Nothing Exit Function

    ErrorHandler: MsgBox "ERROR" Resume Exit_ITERATE_Query_Profile End Function



    • Edited by kqke Wednesday, November 20, 2013 6:50 PM
    Wednesday, November 20, 2013 6:47 PM

Answers

All replies