ma access: sendobject on error go back to form

馋奶兔 提交于 2020-06-28 03:55:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!