Access Outlook Mail

I'm was using the code below to send Outlook 2010 emails form Access 2010. We recently upgraded to Office 2016 and now I get a runtime error 287 on line  Signature = olMailItem.HTMLBody
Thanks



Error 287


 Private Sub DoEmail(Fname As String, Lname As String, Email As String, attach As String)

    Dim olApp As New Outlook.Application
    Dim olMailItem As Outlook.MailItem
    Dim a As Variant
    Dim Signature As String
    Set olMailItem = olApp.CreateItem(0)
   
   
   
    With olMailItem
   .Display
    End With
    Signature = olMailItem.HTMLBody

    olMailItem.To = Email
    olMailItem.Subject = "Monthly Reports"
    olMailItem.HTMLBody = "Find attached your Monthly Cognos and/or eCAPE Monthly Reports. If you have questions please let me know." & "</br></br></br>" & Signature
   
   
    For Each a In Split(attach, ",")
        If Dir(a) <> "" Then
            olMailItem.Attachments.Add a
        End If
    Next
   
   
   olMailItem.Display
   ' olMailItem.Send

    Set olMailItem = Nothing
    Set olApp = Nothing


End Sub
shieldscoAsked:
Who is Participating?
 
shieldscoAuthor Commented:
Below is the code that worked for me in Outlook 2016

  'GET DEFAULT EMAIL SIGNATURE
    Signature = Environ("appdata") & "\Microsoft\Signatures\"
    If Dir(Signature, vbDirectory) <> vbNullString Then
        Signature = Signature & Dir$(Signature & "*.htm")
    Else:
        Signature = ""
    End If
    Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll]
0
 
Jeffrey CoachmanMIS LiasonCommented:
Make sure you have the Microsoft Outlook 2016, (16 perhaps?)
...library loaded in your references.

FWIW , you code ran fine for me in Off 2013
0
 
shieldscoAuthor Commented:
I have a reference to Outlook 16 object library
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Your code works for me in A2016.

Try compacting your database (make a backup first).

If that doesn't work, try to Compile you code. To do that, open the VBA Editor and click Debug - Compile. Fix any errors, and continue doing that until the Compile menuitem is disabled.

You may also need to Decompile your code. To do that, make a shortcut with this as the Target:

"full path to msaccess.exe" "full path to your database" /decompile

Run that, then compile your code again.
0
 
shieldscoAuthor Commented:
After decompiling and compiling I have the same issue... any other suggestions. Could it be Outlook?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
It's possible Outlook is the culprit, but I would doubt it.

You might try creating a new, blank database in 2016 and import everything from the old into the new. Be sure to re-set any references needed in the new database.
0
 
shieldscoAuthor Commented:
After importing into new dB and setting references I get the same error
0
 
Jeffrey CoachmanMIS LiasonCommented:
Odd, ...as your code works for both Scott and I.

Is this issue only on this one computer,...or on any computer>
0
 
Jeffrey CoachmanMIS LiasonCommented:
Try starting your code like this...

   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Outlook.MailItem
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment

   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")

   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Open in new window


This code is directly from the popular MS link on Outlook automation:
https://support.microsoft.com/en-us/help/209948/how-to-use-automation-to-send-a-microsoft-outlook-message-using-access

This code has worked fine for me for years...
0
 
shieldscoAuthor Commented:
You code runs but I don't get the signature which is the issue. I can comment out Signature = olMailItem.HTMLBody and the code executes however there is no signature...
0
 
shieldscoAuthor Commented:
'GET DEFAULT EMAIL SIGNATURE
    Signature = Environ("appdata") & "\Microsoft\Signatures\"
    If Dir(Signature, vbDirectory) <> vbNullString Then
        Signature = Signature & Dir$(Signature & "*.htm")
    Else:
        Signature = ""
    End If
    Signature = CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.