SetWarnings fails on second hit.

grnzbra

Registered User.
Local time
Today, 03:15
Joined
Dec 5, 2001
Messages
376
I have the following code:

Do While Not rs.EOF
If Not IsNull(rs!EMail) Then
str = rs!EMail
DoCmd.SetWarnings False
DoCmd.SendObject acSendReport, rptstr, acFormatSNP, str, , , rsn!SbjLine
rs.Edit
rs!RptMlDt = Date
rs.Update
SkipEMail:

End If
rs.MoveNext
Loop...

Form_Open_Errors:
If Err.Number = 2501 Then
DoCmd.SetWarnings True
GoTo SkipEMail
Else
...
End if

On the first record through, if the e-mail is canceled, it works fine. However, on the next record, I get a message box that says:

Run Time Error '2501':
The SendObject Action was canceled.

I got this on the first run through before I added the SetWarning lines, after which the first e-mail cancelation behaved properly. I tried commenting out the SetWarnings True line, but that didn't stop the error message on the second e-mail.

What's wrong?
 
its the error handler

at the top (above this code) you must have a line

on error goto form_open_errors

now, i'm not sure whether both of these steps are critical BUT
after you have been to the error-handler, you are using a goto to handle the error, so you are STILL in the error handler and therefore the handler will not trigger again - you need to RESUME not GOTO to complete the error handler effectively

you also MAY have to explicit reset the onerror command within the do loop

as I say, i am not sure whether one or both of these is critical, but this is certainly why you are not getting the error handler trapping errors after the first error.

I trust this makes sense
 
Last edited:
Thanks gemma,
It makes sense. Since I need to skip the table update if they cancel (records last date e-mail was sent), I guess I should create a flag in an If statement for the table update and have the error handler set the flag to prevent the update from running. (I checked Help for return and it does allow returning to a specific line, but that sounds like it could be messed up if new code is added at a later date.)
 
i think the resume statement is important to effectively exit the error handler. (must be the way the compiler puts the call on the stack behind the scenes)
 
Are you sure their are no entries with missing mail address not sure if that would do it.
 
The code before it checks for missing e-mails addresses and skips the step if it's missing.
gemma seems to have hit the problem. I set it up his way and it works great.
Yesterday, (I only saw gemma's response at about 10:00 EST today) I moved SendObject line and the error handler to a function that returned a 0 for normal and 1 for a cancelation, and then put the function into the If statement. That worked, but it seems a little convoluted.
 

Users who are viewing this thread

Back
Top Bottom