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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.