Heather Dragon
Heather Dragon

Reputation: 51

ma access: sendobject on error go back to form

I have a database that runs through with no issues, but when the user exits the email instead of emailing the report, an error appears. Right now the code shows:

DoCmd.SendObject acSendReport, "AUS_Main", acFormatPDF, "[email protected]", , , _
     "AUS Checklist and Orders", "My AUS checklist and orders are attached."
DoCmd.Quit acQuitSaveAll

    On Error GoTo Trap

Leave:
    On Error GoTo 0
    Exit Sub

Trap:
    If Err.Number <> 2501 Then MsgBox Err.Description, vbCritical
    Resume Leave

End Sub

I want the program to go back to the last form "15_End", if the user exits without sending, allowing them to make changes if they realize the report is incorrect. If they do send, I want it to continue as is, and quit the database.

Upvotes: 1

Views: 188

Answers (1)

Kostas K.
Kostas K.

Reputation: 8518

Make sure the VBE is configured to break on unhandled errors.

Tools >> Options >> General >> Error Trapping.

Then just manage the 2501 - Operation cancelled error in your method:

Sub Whatever()
    On Error GoTo Trap

    With DoCmd
        .SendObject acSendReport, "AUS_Main", acFormatPDF, "[email protected]", , , _
                                  "AUS Checklist and Orders", "My AUS checklist and orders are attached."
        .Quit acQuitSaveAll
    End With

Leave:
    On Error GoTo 0
    Exit Sub

Trap:
    If Err.Number <> 2501 Then MsgBox Err.Description, vbCritical
    Resume Leave
End Sub 

Upvotes: 1

Related Questions