问题
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, "heather@gmail.com", , , _
"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.
回答1:
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, "heather@gmail.com", , , _
"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
来源:https://stackoverflow.com/questions/62322130/ma-access-sendobject-on-error-go-back-to-form