The following code is eliminating the Yes/No box. It is also acting like SMTP as there is nothing in the Send box and the speed is the same as when I use SMTP. Other code which I have for Outlook brings up the Yes/No and slow to send. The main difference is that code producing the normal Yes/No is not dynamic in reference to the Word doc file.
In both case the Word doc forms the body of the email and the attachment
In both case the Word doc forms the body of the email and the attachment
Code:
Dim OutMail As Object
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
Dim wd As Word.Application
Dim doc As Word.Document
Dim Itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next
Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="c:\StoreLettersGarner\" & Format([Forms]![PrintAndClose]![AA12]))
doc.wdSaveChanges
Set Itm = doc.MailEnvelope.Item
With Itm
.To = Forms!PrintAndClose!A4
.Subject = [Forms]![PrintAndClose]![Text446]
.Attachments.Add ("C:\StoreLettersGarner\" & Format([Forms]![PrintAndClose]![AA12]))
.Save
ID = .EntryID
End With
Set Itm = Nothing
Set Itm = Outlook.Application.Session.GetItemFromID(ID)
Itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If
Set doc = Nothing
Set Itm = Nothing
Set wd = Nothing