Button on form opens a blank email, and I want it to close the form

jmkeuning

New member
Local time
Today, 07:27
Joined
Sep 1, 2016
Messages
9
I have a button on a form (frmEmail) that opens a blank email in Outlook. I want it to close the form (frmEmail) sort of at the same time that the blank email opens.

Can anyone tell me what I should do?

Code:
Private Sub cmdSendEmail_Click()
On Error GoTo Err_cmdSendEmail_Click



    Dim stDocName As String

    stDocName = "Empty_Report"
   ' DoCmd.SendObject acReport, stDocName
   'DoCmd.SendObject acSendNoObject, stDocName, acFormatXLS, to, cc, bcc, subject, body, True
    DoCmd.SendObject acSendNoObject, stDocName, acFormatXLS, Me.EmailTo, "support@google.com", , Me.Subject, Me.Body1 & vbCrLf & vbCrLf & Me.Body2, True
Exit_cmdSendEmail_Click:
    Exit Sub

Err_cmdSendEmail_Click:
    MsgBox Err.Description
    Resume Exit_cmdSendEmail_Click
    
    DoCmd.Close acForm, "frmEmail"
    
End Sub

I also tried all of that but with:

Code:
DoCmd.Close acForm, Me.Name
 
You've got it in the error handler, so it will only execute if there's an error.
 
Is there an obvious (or not so obvious) way to get it out of error handling and work?
 
Sure move it into the body of the procedure, after the SendObject.
 

Users who are viewing this thread

Back
Top Bottom