Send Object Error Handling

DBL

Registered User.
Local time
Today, 19:37
Joined
Feb 20, 2002
Messages
659
I've got a dialog box that sends a report to an email attachment. If the user cancels the event or closes the email without sending it I'm getting a run-time error message 2501. I've put error handling in to trap the code and skip past it but it's not working. It's giving me the run-time error even with the error handling code.

Any ideas?
 
This may seem obvious but does the error handling actually trap the error. have you put a bookmark on the opt out code so you can step through the error path?

If so and it works and runs I can only suggest that that either it is the form generating the error(which you can handle in the Form events) or the actual mail program.

Seems a bit spooky
 
I'm using it on a filter by form dialog box and the end of the code goes:

DoCmd.SendObject acSendReport, "rptMasterfile", "RICH TEXT FORMAT", Forms!frmMasterfiledialog!cboSelectUser.Column(3), , , "Masterfile"

ExitHere:
Exit Sub

errorhandlerexit:
Exit Sub

ErrorHandler:
If Err.Number = 2501 Then
stdresponse = acDataErrContinue
Exit Sub
MsgBox Err.Description
Resume errorhandlerexit

Exit Sub
End If

I tried stepping through it and if I cancel the code it highlights the DoCmd.SendObject line and doesn't get as far as the error handling. I've used this code on other dialog boxes (not filter by form types) and it's worked there.

Don't know what to do next!
 
Its got nothing to do with endif being outside the sub is it?
Try putting a custom Msgbox in the error code to see if it gets there if it doesn't allow you to step thru.

If all else fails you could ask the user to confirm sending prior to the action using an Msgbox, doesn't solve the problem but does get the job done.
 
I tried your code and it seemed to work fine, which is very odd.
Only thing I can suggest is to make sure you have the line:
On Error GoTo ErrorHandler
at the top of your code.

DBL said:
ExitHere:
Exit Sub

errorhandlerexit:
Exit Sub

ErrorHandler:
If Err.Number = 2501 Then
stdresponse = acDataErrContinue
Exit Sub
MsgBox Err.Description
Resume errorhandlerexit

Exit Sub
End If

Also, some of the above code is never going to be used. You could change this to:
Code:
On Error GoTo errorHandler

. . .

exitHandler:
Exit Sub

errorHandler:
If err.number = 2501 then
    stdresponse = acDataErrContinue
Else
    Msgbox err.description
End If
Resume exitHandler

End Sub

Dave
 
Last edited:
Thanks for the suggestions. Not managed to resolve it yet. This is based round a Dynamic Query and I think that may be where the problem is.

Thanks again.
 
Fixed! I had an "On Error GoTo 0" half way through the code that I hadn't spotted (thanks Jack!). Remarked that out and it's doing what it should.

Thanks everybody.
 

Users who are viewing this thread

Back
Top Bottom