Having a tough time trapping DAO errors.

Having a tough time trapping DAO errors.

Post by John Peterso » Wed, 14 Oct 1998 04:00:00



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

 
 
 

Having a tough time trapping DAO errors.

Post by John Peterso » Wed, 14 Oct 1998 04:00:00


Here's a follow-up.  My On Error statement does NOT have a colon at the end
as indicated in my code snippet.  Also, I'm experiencing a run-time error of
3022 on the .Execute method with the dbFailOnError.  I just don't understand
how to trap errors of this nature in my function...


>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


 
 
 

1. Trapping an Error in SQL 2000 - Having Problems!!!!

I have the following simple procedure.

CREATE Procedure spInsertGenericLookup



as

HERE



GO

Am I right in theassumption that because I have made this procedure generic
I cannot trap an error.

The table is a single column lookup table which each record being unique.
What I am trying to do is capture the error when a duplicate value is
inserted into the db( ie 2627). When using the Query Analyser to debug and
step through the code. it terminates at the exec command.

Here is the vb code.

Dim objCmd As New ADODB.Command
  With objCmd
    .ActiveConnection = objConn
    .CommandType = adCmdStoredProc
    .CommandText = "spInsertGenericLookup"


    .Execute    '  TERMINATES HERE


    End If
  End With
  Set objCmd = Nothing

Should I use a before insert trigger (if such thing exists, and how would I
do it?)
Any solutions would be appriciated.
Thanks

Ric.

2. Blob with Progress

3. DAO Error Trapping & Most Common Errors

4. question about log files

5. Trapping SQL error in VB before ADO raises run-time error

6. SQL Web assistant - cannot drop Web_YYMMDD...

7. Error Trapping - Can you trap a DTS Package error using SQLDMO running a job

8. TX-SAN ANTONIO-109765--SQL-RDBMS-ORACLE-SYBASE-MS SQL Server-DB2-DATA WAREHOUSE CONSULTANTS

9. Error Trapping: MS Access errors not trapped in VB code

10. DAO No Record error trapping

11. Trapping DAO Errors

12. Trap run-time errors in a trigger

13. Can someone show me how to trap an run-time error