Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendObject Error Message 1

Status
Not open for further replies.

Magnetar

Programmer
Sep 22, 2001
73
GB
Evening all

Can someone advise me on the following problem, please?

Am using the SendObject method to dispatch attachments within an email (MS Word Output from a report). The process works find UNTIL the user decides to change their mind and not send an e-mail(!), i.e. the message is closed at top right-hand of Outlook form [x].

I get what I can only describe as/or what seems to be like an 'Access' message, (as opposed to 'error-handling' message, - my error-handling code normally display the error number as well as the location from which error is triggered):
" The SendObject action was cancelled..
You used a method of the DoCmd oject ot carry out an action Visual Basic, but then clicked Cancel in a dialog box.
For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form."

I then click 'OK' to this message, and the whole form is locked/frozen. (Have to [ctrl]+[alt]+[delete] out of the database system to close & then reopen].

I've been thro' this over & over again, trying to trap the error 2501, debugging, breakpoints, etc. Here is an example of my code:

Private Sub cmdRunCode_Click()
'Open Report then send e-mail.

On Error GoTo cmdRunCodeErr

If IsNull(Me.cboReportSelectionType) Then

MsgBox "Please Select a ReportType", vbOKOnly, "ReportType Needed for Report."
Exit Sub
Else
DoCmd.SendObject acReport, "rptEmailReportByGivenReportType", "RichTextFormat(*.rtf)"

End If

cmdRunCodeExit:
Exit Sub
cmdRunCodeErr:

'This traps the Output to Error message
If Err = 2501 Then
MsgBox "You've chosen not to send this email", vbOKOnly, "Message not sent"
Exit Sub
Else
MsgBox "Error within Private Sub cmdRunCode_Click(). Error No: " & Err.Number & ". Error: " & Err.Description & "."
Resume cmdRunCodeExit

End If


Have searched the forums on this site, etc & have taken note of all the (very useful) advice on error-trapping & so on, but to no avail.

Can anyone help? Many thanks in advance.

Magnetar [atom]



 
Remove the Exit sub within the errorhandler. I think, without the resume (just exit), the error isn't handled, and passed back, giving the message.

Roy-Vidar
 
Hm - I didn't pay enough attention - one would probably need to ensure a resume, so perhaps also move the resume line:

[tt]If Err = 2501 Then
MsgBox "You've chosen not to send this email", vbOKOnly, _
"Message not sent"
' Exit Sub - Remove
Else
MsgBox "Error within Private Sub cmdRunCode_Click(). Error No: " & _
Err.Number & ". Error: " & Err.Description & "."
End If
Resume cmdRunCodeExit ' Move[/tt]

If it doesn't help, perhaps have a look at Tools | Options in VBE, the General tab, and see that Break on Unhandled Errors are selected.

Roy-Vidar
 
RoyVidar, hi there!

Many thanks for all of your suggestions this week, which I did try.
I've somehow managed to 'get around' the above problem (so to speak), by minimising another form during the 'e-mailing' process.
(Very strange, - still don't know why this has worked, or why my form froze in 'modal' state to begin with, or even why I obtained the error msge without the 'err.number' value, - but there you go!).

Once again many thanks for your help.

Kind regards, - Magnetar [atom]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top