Access 97 Class Mod Error Trap Weirdness 
Author Message
 Access 97 Class Mod Error Trap Weirdness

I have an interesting situation in a class module with an error trap.
I have a function/method in a class mod that has an error trap like
this:

Private Function Add() as Boolean

On Error Goto ProcErr

Dim wrksp as Workspace
Dim strSQL as String

strSQL = "<INSERT INTO....>"

Set wrksp = DBEngine.Workspaces(0)

wrksp.BeginTrans

  db.execute strSQL, dbFailOnError
  db.execute strSQL, dbFailOnError

  wrksp.CommitTrans, dbForceOSFlush

ProcEnd:

  wrksp.Rollback
  Set wrksp = Nothing

ProcErr:

    MsgBox Err.Number & vbcrlf & Err.Description
    Resume ProcEnd

End Function

The problem is that the code runs through the executions and runs
right past the ProcEnd: line label and tries to execute the sub
routine code:

wrksp.Rollback
Set wrksp = Nothing

I don't have this type of problem in standard modules or form class
modules. Only in my user defined class mods.

Anybody out there come accross this behavior?

Currently I have to use On Error Resume Next and then look at the
Err.Number after the DB.Execute to determine if the operations were
successful and CommitTrans or Rollback as required. Seems a bit silly
to have to do it that way.

If anyone has seen this, has a theory or knows what cause this I would
love to hear from you!

Thanks in advance!

RLM



Sun, 01 Aug 2004 22:16:37 GMT  
 Access 97 Class Mod Error Trap Weirdness
Hi RLM,
You're not telling it to stop. You have to place
an Exit Function statement where you want the code to stop.
This is true with any code, not just in a class.

HTH
Dan Artuso, MVP


Quote:
> I have an interesting situation in a class module with an error trap.
> I have a function/method in a class mod that has an error trap like
> this:

> Private Function Add() as Boolean

> On Error Goto ProcErr

> Dim wrksp as Workspace
> Dim strSQL as String

> strSQL = "<INSERT INTO....>"

> Set wrksp = DBEngine.Workspaces(0)

> wrksp.BeginTrans

>   db.execute strSQL, dbFailOnError
>   db.execute strSQL, dbFailOnError

>   wrksp.CommitTrans, dbForceOSFlush

> ProcEnd:

>   wrksp.Rollback
>   Set wrksp = Nothing

> ProcErr:

>     MsgBox Err.Number & vbcrlf & Err.Description
>     Resume ProcEnd

> End Function

> The problem is that the code runs through the executions and runs
> right past the ProcEnd: line label and tries to execute the sub
> routine code:

> wrksp.Rollback
> Set wrksp = Nothing

> I don't have this type of problem in standard modules or form class
> modules. Only in my user defined class mods.

> Anybody out there come accross this behavior?

> Currently I have to use On Error Resume Next and then look at the
> Err.Number after the DB.Execute to determine if the operations were
> successful and CommitTrans or Rollback as required. Seems a bit silly
> to have to do it that way.

> If anyone has seen this, has a theory or knows what cause this I would
> love to hear from you!

> Thanks in advance!

> RLM



Sun, 01 Aug 2004 22:37:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Pass integer Value from forms Class mod to report class mod

2. Trapping for Errors in Access 97

3. Mod 10 Check Routine using VB for Access 97

4. Automation Error when automating Word 97 from Access 97

5. Mail merge error: Access 97 to Word 97

6. How to Handle AppointmentItem error Access 97 - Outlook 97 across Exchange

7. Conversion error from Access 2000 to Access 97

8. Access 97 to Access 200 converting Error Code Handling

9. Class Module Access 97

10. Access 2000 converted to Access 97 report query data type errors

11. Classes in Access 97

12. Access 97 Class Modules (Visio)

 

 
Powered by phpBB® Forum Software