Print A For (docm), Send Email Attachment And Close For Without Saving

Joined
Jun 15, 2017
Messages
2
Reaction score
0
I have this code which does everything except when it close the form it saves the information. Email and print work fine.
I cannot figured out why it keeps saving the data. Using a command button to do all this. Form has checkboxes, text fields.


Public Sub commandbutton1_click()
ActiveDocument.PrintOut Copies:=1
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "HelpDesk Ticket Submitted"
.Body = "" & vbCrLf & _
"" & vbCrLf & _
""
.To = "(e-mail address removed)"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
If Documents.Count = 1 Then
Application.Quit SaveChanges:=wdDoNotSaveChanges
Else
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End If

End Sub
 
Joined
Jun 15, 2017
Messages
2
Reaction score
0
Also if I tried adding another command button, if I push the 1st command button that sends e-mail and attaches the form, then hit the 2nd command button that closes the form it still saves the data.
 

macropod

Microsoft MVP
Joined
Mar 2, 2012
Messages
580
Reaction score
50
You cannot attach an unsaved document to an email. You need to save it and, after sending the email, you can then delete the document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top