Button on form opens a blank email, and I want it to close the form (1 Viewer)

jmkeuning

New member
Local time
Today, 10:03
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:03
Joined
Aug 30, 2003
Messages
36,125
You've got it in the error handler, so it will only execute if there's an error.
 

jmkeuning

New member
Local time
Today, 10:03
Joined
Sep 1, 2016
Messages
9
Is there an obvious (or not so obvious) way to get it out of error handling and work?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:03
Joined
Aug 30, 2003
Messages
36,125
Sure move it into the body of the procedure, after the SendObject.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:03
Joined
Aug 30, 2003
Messages
36,125
Happy to help!
 

Users who are viewing this thread

Top Bottom