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
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