Error Handler problem

zdog

Registered User.
Local time
Today, 05:30
Joined
Jan 11, 2005
Messages
23
Hi All,

My question is with regards to the error handler that I have. The code below is only a partial extract from the code on the form.

Essential the code attaches a report to an outlook message. If the user doesn't send the email, it runs through the error handler and asks the user to resend the email if they click the retry button or closes the form is they click cancel.

I was testing the code and so I closed the email without sending, the message box successfully appeared asking if I wanted to resend the email or close the form, I hit rerty and again closed the email without sending but this time instead of displaying my custom error message it displayed the default message generated by access. "Run Time error: 2501 sendobject method was canceled."

Does anyone notice anything incorrect in my error handler that is causing access not to step through the error handler on the second attempt. Its not really a big issue but I'm just curious to know whats wrong. Hope I have explained the problem in sufficient detail.

Thanks for the help,
ZDog

report:
On Error GoTo Error_handler

DoCmd.SendObject acReport, "repPFA", "RichTextFormat(*.rtf)", Me.cmbAuthorizer.Value, , , "PFA Request", , True
DoCmd.GoToRecord , , acNewRec
MsgBox "Information successfully updated.", vbInformation

Error_handler:
If Err.Number = "2501" Then
response = MsgBox("Email not sent. Please send the PFA to the designated authorizer in order to process the request.", 21, "Error!")
If response = vbRetry Then
GoTo report
ElseIf response = vbCancel Then
cmdClose_Click
End If
Exit Sub
End If
 
Looks like you are answering the cancel with a cancel.

Instead of...
ElseIf response = vbCancel Then
cmdClose_Click
End If
Exit Sub
End If

Try...
Else
cmdClose_Click
End If
Exit Sub
End If

I also think this a cleaner method...
Code:
Error_handler:
If Err.Number = 2501 Then
    If MsgBox("Email not sent. Please send the PFA to the designated authorizer in order to process the request.", vbCritical + vbRetryCancel, "Error!") = vbRetry Then
        GoTo Report
    Else
        cmdClose_Click
    End If

Exit Sub

End If
 
Last edited:
Hi Hudson

I changed to code to the cleaner version that you suggested however I still run into the same problem. For some reason access doesn't seem to recognize the line On error goto Error_handler on the second attempt. Like I mentioned earlier, works just fine the first time I cancel the sendobject action.

Thanks for the suggestion though
ZDog
 
Without test it the problem seems to be that the error object is still dirty when the second error occurs.

Try changing: -

GoTo Report

To: -

Resume Report

The Resume will clear the error and Access should then be able to process the new error.

Hope that little bit of airware works.

Regards,
Chris.
 
ive had a similar problem b4 where access would display the built in error on the second run through the error handler.

It wouldnt use my error handling.

If someone could offer some light that would be handy
 
Problem solved. :)
Thanks Chris, using "resume" instead of "goto" solved the problem.
meboz you might want to try it out as well if your error handler is structured similar to mine, worked for me hopefully it will work for you too.

Thanks again guys,
ZDog
 

Users who are viewing this thread

Back
Top Bottom