SendObject action was canceled

G

Guest

In a form, I give the user the opportunity to e-mail the data from the form
to someone. If they change their mind after the e-mail application opens,
they can cancel the application. When they do this, I get the following
error:

Run-time error '2501':
The SendObject action was canceled.

That's understandable and ok, but the option buttons on the msgbox are "End"
or "Debug". I just want the process to end. How can I force it to end
without the error message coming up?

tia,
 
M

M.L. Sco Scofield

Try this:

'<SampleCode>
Private Sub cmdYourButtonName_Click()
On Error GoTo ErrorRoutine

Const errUserCanceledAction As Long = 2501

DoCmd.SelectObject '*** Your parameters ***

RoutineExit:
Exit Sub

ErrorRoutine:
If Err.Number = errUserCanceledAction Then
'Do nothing
Else
MsgBox "Error number: " & Err.Number & vbCrLf & vbCrLf & _
Err.Description, vbCritical, "Error"
End If

Resume RoutineExit

End Sub
'</SampleCode>

This also works for canceled reports when you use the NoData event.

Good luck.

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
M

M.L. Sco Scofield

You're welcome.

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
G

Guest

I have tried this but I cant get ANY trapping working, code alway interrupts
and I wonder why the code never makes it to ErrorRoutine:

Private Sub Cmd0_Click()
On Error GoTo ErrorRoutine

DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", , , "header",
"hello", True

RoutineExit:
Exit Sub

ErrorRoutine:
If Err.Number = 2501 Then
'Do nothing
Else
MsgBox "Error number: " & Err.Number & vbCrLf & vbCrLf & _
Err.Description, vbCritical, "Error"
End If

Resume RoutineExit

End Sub
 

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