Outlook Automation from Access

Mr. B

"Doctor Access"
Local time
Today, 09:03
Joined
May 20, 2009
Messages
1,932
I am usinig the code below to create a new instance of Outlook and an email message with an attachment and send it. I have also implemented the use of "ClickYes" to fully automate the process. All of this works exacly as expected when I run it here. I have tested it with Outlook open and with it closed and the code works as expected.

However, when my client attempts to use this same code an error is reported if Outlook is not open. If Outlook is open it seems to work as designed. This code is supposed to create a new instance of the Outlook object, use that object to create the new email and when the email is send, kill that instance of Outlook.

Sub SendEmailMessage(strEmailAddress As String, _
strEmailCCAddress As String, _
strEmailBccAddress As String, _
strSubject As String, _
strMessage As String, _
blnDisplayMessage As Boolean, _
Optional strAttachmentFullPath As String)
On Error GoTo ErrorMsgs
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application 'GetObject(,"Outlook.Application")
Dim email As Outlook.MailItem
Set email = olApp.CreateItem(olMailItem)

email.Recipients.Add strEmailAddress
email.Subject = strSubject
email.Body = strMessage
email.Attachments.Add strAttachmentFullPath
If blnDisplayMessage = True Then
email.Display
Else
'* Send message by putting it in the Outbox
email.Send
End If
ExitHere:
Set email = Nothing
Set olApp = Nothing
Exit Sub
ErrorMsgs:
MsgBox Err.NUMBER, Err.Description
GoTo ExitHere
End Sub

References have been set and checked with no "missing" ones found and no other code type errors occuring.

I am wondering if ther can be some setting on the client's machine that may be causing this.

Any thoughts are welcome and appreciated.

Thanks, in advance.
 
"an error is reported if Outlook is not open"
What error??? Doesn't it seem important to report what the error is???
Cheers,
 
Well, yes, it might be important, but at the time I did not have the exact error but thought I'd just throw it out there.

The error is: Runtime error: #13 Type Missmatch.

It is refering to the line:
Set email = olApp.CreateItem(olMailItem)
 

Users who are viewing this thread

Back
Top Bottom