I used a template file stored in my PC to create and email message and display it so i could double check all info before sending for the last two years. Now suddenly it doesn't work anymore! I am getting the error saying the object could not be found on the .Display line.
if i add On Error Resume Next before the with omail then i get no error and if i then open Outlook, the message will be in my Drafts, but will not be in HTML format.
It worked last year and the year before. The last time I KNOW it worked was 12/28/2018 (just a couple months ago!).
I did update my office from version 1803 to the newest version 1901.
I have quadruple checked my attachment and it is generating the correct file path and it is attaching it to the email.
But the email will not display anymore and is always in plain text. Any help would be greatly appreciated!
Code:
Private Sub cmd_EmailInspections_Click()Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
Dim oAtt As Outlook.Attachment
Dim mySQL As String
Dim myTo As String
Dim myCC As String
Dim BodyWithoutSignature As Variant
Dim myAtt As String
Dim myDivisionInt As Integer
Dim myDivision As String
Dim myYear As String
Dim myDate As String
Dim myOldName As String
Dim myNewName As String
Dim myNewNewName As String
Dim myNewOldName As String
Set oApp = New Outlook.Application
myYear = Me.txt_MyYear
Select Case myYear
Case 2018
Set oMail = oApp.CreateItemFromTemplate("C:\Scripts\Outlook\AnnualInspections2018.oft")
Case 2017
Set oMail = oApp.CreateItemFromTemplate("C:\Scripts\Outlook\AnnualInspections2017.oft")
Case 2019
Set oMail = oApp.CreateItemFromTemplate("C:\Scripts\Outlook\AnnualInspections2019.oft")
End Select
myTo = Me.txt_Email
myDivisionInt = DLookup("DivisionID", "tblCustomers", "[PK_Customer] = " & Me.cbo_Customer)
myDate = Format(Date, "yyyy-mm-dd")
myDivision = REDACTED INFO
myCC = REDACTED INFO
myAtt = "R:\" & myYear & "\" & myDivision & "\.Complete\" & Me.cbo_Customer.Column(1) & " - Annual Inspections " & myYear & ".zip"
With oMail
BodyWithoutSignature = .HTMLBody
End With
With oMail
.Display
.To = myTo
.CC = myCC
.Recipients.ResolveAll
.BodyFormat = olFormatHTML
.Attachments.Add (myAtt)
.HTMLBody = BodyWithoutSignature
.Save
End With
Set oMail = Nothing
Set oApp = Nothing
END SUB
Edit: Now it is working but it displays a double signature. The signature in the template is a different signature than my default signature.
Edit Again: Now Solved, I needed to move .Display immediately under With oMail.