I use VBA in MS Access to send e-mails. Relevant code for error is:
There code at the start of the function to open Outlook if it is not open.
Code runs fine under Windows XP/Access 2003/Outlook 2003 whether or not Outlook is initially open and whether or not there is an attachment.
Under Windows Vista/Access 2007/Outlook 2007 and Windows 7/Access 2010/Outlook 2010 the code runs fine with or without an attachment if Outlook is initially open. If Outlook is not open, code works fine if there is an attachment but fails if there is no attachment.
Code:
Set oItem= objOL.CreateItem(0) ' Const olMailItem
With oItem
errMsg = "Error populating Microsoft Outlook mail item components."
.To = Trim(emAddress)
.Subject = emSubject
.Body = MergeBody(PIN, msgBody)
If Not Isnull(attachmentPath) then
.attachments.Add attachmentPath
End if
errMsg = "Error sending Microsoft Outlook mail item."
.Send
End With
Code runs fine under Windows XP/Access 2003/Outlook 2003 whether or not Outlook is initially open and whether or not there is an attachment.
Under Windows Vista/Access 2007/Outlook 2007 and Windows 7/Access 2010/Outlook 2010 the code runs fine with or without an attachment if Outlook is initially open. If Outlook is not open, code works fine if there is an attachment but fails if there is no attachment.
Comment