I have a case where one user would like to receive notifications of when deliveries are added to an Access Database. The simplest method I could think of was to set up an automated email via Outlook 2010. The following code is what I have in place:
Dim oApp As Outlook.Application Dim oMail As MailItem Dim varDnoteRef2 As String Dim varuser As String varuser = DLookup("[Employee_Name]", "employees", "[Employee_ID]=" & TempVars!gloggedin) varDnoteRef2 = DLast("Supplier_Dnote_Ref", "Supplier_Dnotes") Set oApp = CreateObject("Outlook.application") Set oMail = oApp.CreateItem(olMailItem) oMail.Body = "A Delivery Note has been added to the Database by " & varuser & " on " & Now() & "." & _ vbNewLine & "Delivery Note: " & varDnoteRef2 oMail.Subject = "Automatic Notification: Delivery Note" oMail.To = "Example@Email.co.uk" oMail.Send Set oMail = Nothing Set oApp = Nothing This code works perfectly when the person who activates the code has Outlook open. However, when the user doesn't have Outlook launched the user gets an error at the oMail.send line.
error # 287 error line 0 application-defined or object-defined error.
What they get is a small icon on the desktop that is the outlook symbol with a gear/cog and message saying another program or application is using outlook. Which is what I expect. But why does it fail on the send?
How can I get around this error/ is there a solution?
Edit (Update)
What is more strange is that when I step through my code using F8. IT WORKS!! But still not when I call the code from a form action e.g. button_on_click