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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time Error 2501 SendObject Action Cancelled

Status
Not open for further replies.

Costefran

Technical User
Jan 2, 2008
197
GB
Hello

Can anyone help

I have a command button click event for sending an email

If the user decides to cancel the email the following msgbox appears saying

"Run-Time Error 2501"
"The SendObject Action was cancelled"
END or Debug

I would like to prevent this from happening but not sure how to

I have posted my code below as I thought it may help

Private Sub Cost_Authorisation_Queries_Click()
On Error GoTo Err_Cost_Authorisation_Queries_Click

Dim stDocName As String
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If [Forms]![Cost Authorisation Non - Project Form]![Vendor Authorisation] = "Query" Then DoCmd.SendObject acSendReport, "Vendor Comments_Query Report", acFormatSNP, , , , "Vendor Query Raised for " & [PREFIX] & [ID], "Vendor Query Raised for " & [PREFIX] & [ID] & [vbCrLf] & [vbCrLf] & "Please see comments below which are also shown on the attached document" & [vbCrLf] & [vbCrLf] & [Comments], , False
If [Forms]![Cost Authorisation Non - Project Form]![ML Authorisation 1] = "Query" Then DoCmd.SendObject acSendReport, "ML Authorisation1 Comments_Query Report", acFormatSNP, , , , "ML Query Raised for " & [PREFIX] & [ID], "ML Query Raised for " & [PREFIX] & [ID] & [vbCrLf] & [vbCrLf] & "Please see comments below which are also shown on the attached document" & [vbCrLf] & [vbCrLf] & [Comments], , False
If [Forms]![Cost Authorisation Non - Project Form]![ML Authorisation 2] = "Query" Then DoCmd.SendObject acSendReport, "ML Authorisation 2 Comments_Query Report", acFormatSNP, , , , "ML Query Raised for " & [PREFIX] & [ID], "ML Query Raised for " & [PREFIX] & [ID] & [vbCrLf] & [vbCrLf] & "Please see comments below which are also shown on the attached document" & [vbCrLf] & [vbCrLf] & [Comments], , False
Exit_Cost_Authorisation_Queries_Click:
Exit Sub
Err_Cost_Authorisation_Queries_Click:
MsgBox Err.Description
Resume Exit_Cost_Authorisation_Queries_Click
End Sub
 
You can trap the error.

Code:
Err_Cost_Authorisation_Queries_Click:
Select Case Err.Number
Case 2501
    MsgBox "You chose to cancel."
Case Else
    MsgBox Err.Description
End Select

    Resume Exit_Cost_Authorisation_Queries_Click

End Sub
 
Many thanks but cannot et this to work

I have pasted my understing of your suggested code embedded in the original code but not sure this is correct

Private Sub Cost_Authorisation_Queries_Click()
On Error GoTo Err_Cost_Authorisation_Queries_Click

Dim stDocName As String
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If [Forms]![Cost Authorisation Non - Project Form]![Vendor Authorisation] = "Query" Then DoCmd.SendObject acSendReport, "Vendor Comments_Query Report", acFormatSNP, , , , "Vendor Query Raised for " & [PREFIX] & [ID], "Vendor Query Raised for " & [PREFIX] & [ID] & [vbCrLf] & [vbCrLf] & "Please see comments below which are also shown on the attached document" & [vbCrLf] & [vbCrLf] & [Comments], , False
If [Forms]![Cost Authorisation Non - Project Form]![ML Authorisation 1] = "Query" Then DoCmd.SendObject acSendReport, "ML Authorisation1 Comments_Query Report", acFormatSNP, , , , "ML Query Raised for " & [PREFIX] & [ID], "ML Query Raised for " & [PREFIX] & [ID] & [vbCrLf] & [vbCrLf] & "Please see comments below which are also shown on the attached document" & [vbCrLf] & [vbCrLf] & [Comments], , False
If [Forms]![Cost Authorisation Non - Project Form]![ML Authorisation 2] = "Query" Then DoCmd.SendObject acSendReport, "ML Authorisation 2 Comments_Query Report", acFormatSNP, , , , "ML Query Raised for " & [PREFIX] & [ID], "ML Query Raised for " & [PREFIX] & [ID] & [vbCrLf] & [vbCrLf] & "Please see comments below which are also shown on the attached document" & [vbCrLf] & [vbCrLf] & [Comments], , False
Exit_Cost_Authorisation_Queries_Click:
Exit Sub
Err_Cost_Authorisation_Queries_Click:
Select Case Err.Number
Case 2501
MsgBox "You chose to cancel."
Case Else
MsgBox Err.Description
End Select

Resume Exit_Cost_Authorisation_Queries_Click

End Sub

I have deleted this part of the code (below)
Err_Cost_Authorisation_Queries_Click:
MsgBox Err.Description
Resume Exit_Cost_Authorisation_Queries_Click
End Sub
 
Hello

I have now found the option to break on unhandled erros

Is there any downside to selecting this

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top