Is my Error trap working???

C

Chris K

I'm having a few concerns about my Access application - It doesn't seem to
be erroring as it should


I have just written small routine with complete error trapping:

Private Sub Invite_Click()
On Error GoTo CantPrintInvite
With CurrentDb.QueryDefs("StdQuery").Parameters
.SQL = "SELECT [JHPclients.].* From [JHPclients.] WHERE [booked] = "
& Bookings <<<<<Errored here
End With
Application.FollowHyperlink "Letter Invite to induction.doc", , True
Exit_Invite:
Exit Sub
CantPrintInvite:
MsgBox "Cant Print Invite: " & Err.Description
Resume Exit_Invite

End Sub

I caused a deliberate error but the trap was ignored completely and Access
caused regular error and into debug mode on the line indicated

Is there something obvious here that I'm not seeing???
 
S

Stuart McCall

Chris K said:
I'm having a few concerns about my Access application - It doesn't seem to
be erroring as it should


I have just written small routine with complete error trapping:

Private Sub Invite_Click()
On Error GoTo CantPrintInvite
With CurrentDb.QueryDefs("StdQuery").Parameters
.SQL = "SELECT [JHPclients.].* From [JHPclients.] WHERE [booked] =
" & Bookings <<<<<Errored here
End With
Application.FollowHyperlink "Letter Invite to induction.doc", , True
Exit_Invite:
Exit Sub
CantPrintInvite:
MsgBox "Cant Print Invite: " & Err.Description
Resume Exit_Invite

End Sub

I caused a deliberate error but the trap was ignored completely and Access
caused regular error and into debug mode on the line indicated

Is there something obvious here that I'm not seeing???

..SQL is a QueryDef property, not part of the parameters collection. Change
this line:

With CurrentDb.QueryDefs("StdQuery").Parameters

to:

With CurrentDb.QueryDefs("StdQuery")
 
C

Chris K

Allen Browne said:
What setting do you have for Error Trapping under Tools | Options |
General (from the code window)?

Set to:
Break on Unhandled Errors

My intention was to use this database on many machines with 3rd party users
and prevent errors from crashing the whole program (certainly dont want it
entering debug mode)

You seem to suggest that error handling is dependant upon Application
settings (the machine it is run on) so my time could be wasted trying to
handle errors

But it is already set to break on Unhandled errors - and Access still halted
the program and entered debug mode (precisely what i dont want) - is there
something wrong with my computer??????????

With regarding the code, it had a lot of errors that I've now sorted - my
only concern is whether I have handled errors correctly & why I can't seem
to control what Access feels like doing or whether to just trade my computer
in for a newer one?



I'd also suggest you break down a complex line like the one that contained
the error into several, as it simplifies debugging when something does go
wrong. For this particular line, I'd use a string variable for the SQL
statement (so I can Debug.Print it), and a db variable for CurrentDb (so I
can explicitly set it back to Nothing at the end of the procedure.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Chris K said:
I'm having a few concerns about my Access application - It doesn't seem
to be erroring as it should


I have just written small routine with complete error trapping:

Private Sub Invite_Click()
On Error GoTo CantPrintInvite
With CurrentDb.QueryDefs("StdQuery").Parameters
.SQL = "SELECT [JHPclients.].* From [JHPclients.] WHERE [booked] =
" & Bookings <<<<<Errored here
End With
Application.FollowHyperlink "Letter Invite to induction.doc", , True
Exit_Invite:
Exit Sub
CantPrintInvite:
MsgBox "Cant Print Invite: " & Err.Description
Resume Exit_Invite

End Sub

I caused a deliberate error but the trap was ignored completely and
Access caused regular error and into debug mode on the line indicated

Is there something obvious here that I'm not seeing???
 
D

Douglas J. Steele

Stuart McCall said:
Chris K said:
I'm having a few concerns about my Access application - It doesn't seem
to be erroring as it should


I have just written small routine with complete error trapping:

Private Sub Invite_Click()
On Error GoTo CantPrintInvite
With CurrentDb.QueryDefs("StdQuery").Parameters
.SQL = "SELECT [JHPclients.].* From [JHPclients.] WHERE [booked] =
" & Bookings <<<<<Errored here
End With
Application.FollowHyperlink "Letter Invite to induction.doc", , True
Exit_Invite:
Exit Sub
CantPrintInvite:
MsgBox "Cant Print Invite: " & Err.Description
Resume Exit_Invite

End Sub

I caused a deliberate error but the trap was ignored completely and
Access caused regular error and into debug mode on the line indicated

Is there something obvious here that I'm not seeing???

.SQL is a QueryDef property, not part of the parameters collection. Change
this line:

With CurrentDb.QueryDefs("StdQuery").Parameters

to:

With CurrentDb.QueryDefs("StdQuery")

In other words, I doubt that your code compiles correctly, so it's not
surprising the VBA Error Trapping doesn't do anything!.
 
Joined
Aug 21, 2010
Messages
1
Reaction score
0
Douglas J. Steele said:
"Stuart McCall" <[email protected]> wrote in message
news:VWHbo.139567$qO1.75654@hurricane...
> "Chris K" <[email protected]> wrote in message
> news:RfGbo.102330$KP3.49803@hurricane...



In other words, I doubt that your code compiles correctly, so it's not
surprising the VBA Error Trapping doesn't do anything!.



I see what you mean - it first had to be able to compile it properly before my user error routines are effective at all - that does make more sense now
 
C

Chris K

In other words, I doubt that your code compiles correctly, so it's not
surprising the VBA Error Trapping doesn't do anything!.

--

I see what you mean - it first had to be able to compile it properly before
my user error routines are effective at all - that does make more sense now
 
D

David W. Fenton

What setting do you have for Error Trapping under Tools | Options
| General (from the code window)?

Set to:
Break on Unhandled Errors

I'd recommend setting this to:

Break in Class Module

If you have no standalone class modules in your app, it will behave
just like Break on Unhandled Errors, but if you someday add any,
you'll want it to break on the errors inside the class modules, not
just on the line calling the class module.

I've never understood the point of having this choice, honestly. It
always seemed to me that there was no advantage at all to *not*
breaking within a class module.
 
D

David W. Fenton

I caused a deliberate error but the trap was ignored completely
and Access caused regular error and into debug mode on the line
indicated

Since you have said that you have application-level error handling
on (as Allen recommended), try this code, but run it when there are
NO FORMS OPEN (if there's an open form, you'll get a series of other
errors because of the invalid recordsource, and I don't want to
complicate things):

Public Sub TestError()
On Error GoTo errHandler

Forms(0).RecordSource = "Gibberish"

exitRoutine:
Exit Sub

errHandler:
MsgBox Err.Number & ": " & Err.Description, vbExclamation, "Error"
Resume exitRoutine
End Sub

If that produces an error, then there's something wrong with your
original code. If it *doesn't*, then I'm not sure what's going on.
 
D

David W. Fenton

I see what you mean - it first had to be able to compile it
properly before my user error routines are effective at all - that
does make more sense now

You should be compiling regularly. Do yourself a favor and add the
compile button to your VBE toolbar and then you can compile
frequently.
 
J

John W. Vinson

But it is already set to break on Unhandled errors - and Access still halted
the program and entered debug mode (precisely what i dont want) - is there
something wrong with my computer??????????

Chris, that's exactly what "break on unhandled errors" is designe to do - stop
and enter debug mode when you encounter an untrapped error. Am I
misunderstanding?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top