Run Time Error 287 When Sending Emails (1 Viewer)

Cavman

Registered User.
Local time
Today, 17:36
Joined
Oct 25, 2012
Messages
66
Hi,

I have the following code in a module that sends out various email updates to me when I'm off site. On my PC it works perfectly whether I have Outlook open or not. I've installed the database on several other machines, but I'm getting a Run Rime Error 287 on the .Send line if the user has Outlook closed. Can anyone tell me if there's a setting somewhere in Outlook or Access that needs changing? Or is there something that can be changed in the code to ensure the email sends whether Outlook is open or not?

Code:
Public Sub SendEmailNotification(strSubject as String, strMessage as String, strAddress as String)
 
Dim olEmailApp As Object
Dim olMsg As Object
Dim strEmailBody As String
Set olEmailApp = CreateObject("Outlook.Application")
Set olMsg = olEmailApp.CreateItem(0)

With olMsg
    .Subject = strSubject
    .HTMLBody = strMessage
    .To = strAddress
    .Send
End With

Set olMsg = Nothing
Set olEmailApp = Nothing

End Sub


Thanks for any help in advance!
 

pr2-eugin

Super Moderator
Local time
Today, 17:36
Joined
Nov 30, 2011
Messages
8,494
I think the problem lies with Access automation, When you try to send an Email via VBA Code, the Security settings of Outlook is designed in a way that it needs your consent to send them out. If this is not obtained, email will not be sent and results in a Runtime error.

There are other alternatives like using a Third Party software or using CDO emails. http://www.rondebruin.nl/win/s1/cdo.htm
 

Users who are viewing this thread

Top Bottom