Hello, all!
I have a VB5 (SP3) project using DAO 3.51. I am trying to trap errors when
I execute Action Queries.
To test my error handling, I have a table that I'm trying to insert into
with a primary key defined. I am attempting to insert a *duplicate* record
(to violate the primary key). My code looks like the following:
Public Function ExecuteQueryAction(qd As QueryDef, Optional sFunctionName As
Variant) As Boolean
On Error GoTo Error_ExecuteQueryAction:
ExecuteQueryAction = False
Call g_wksWorkspace.BeginTrans
Call qd.Execute(dbFailOnError)
Call g_wksWorkspace.CommitTrans(dbForceOSFlush)
ExecuteQueryAction = True
Exit_ExecuteQueryAction:
Exit Function
Error_ExecuteQueryAction:
Call DisplayError(Error$, sFunctionName)
Call g_wksWorkspace.Rollback
Resume Exit_ExecuteQueryAction
End Function
Where qd is a pre-defined QueryDef object that I successfully created. My
problem appears as if the On Error statement isn't working! That is, I'll
get an error message indicating that I've violated the primary key from DAO,
but my function isn't trapping the error! The message box (under the Visual
Basic program, seemingly generated by the internals of DAO) gives me an
option to End or Debug. When I click on Debug, it puts me on the .Execute
method, NOT my error handler. When I take out the dbFailOnError, I don't
get *any* errors, and the DBEngine.Errors collection doesn't appear to
contain the error that I know should be there. How do I trap errors of this
nature?
What the heck am I doing wrong? Any help or advice would be HUGELY
appreciated! Thank you.
John Peterson