objOutlook.CreateItem(olMailItem) error

  • Thread starter Thread starter Reg
  • Start date Start date
R

Reg

Using automation I am successfully sending emails through Outlook from
Access.
Initially it seemed that there was no need for Outlook to be open for me to
do this.
Now, however I am getting an error -2113732604 at the line

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

It does not occur if I have Outlook open.
I would be grateful if someone could suggest what might have happened to
change things such that I now have to have Outlook open to avoid this error.

Thanks
Reg
 
TC said:
What is the full text of the error?

Show us the surrounding code. It's hard to comment, from just one line.

TC (MVP Access)
http://tc2.atspace.com

Thank you - here it is:

Sub sbSendMessage(Optional AttachmentPath)
'' from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta/html/odc_ac_olauto.asp

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

On Error GoTo ErrorMsgs

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.

This next line is the one at which I get the eror message

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(txtTo)
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
If Not txtCC = "" Then
Set objOutlookRecip = .Recipients.Add(txtCC)
objOutlookRecip.Type = olCC
End If
If Not txtBCC = "" Then
Set objOutlookRecip = .Recipients.Add(txtBCC)
objOutlookRecip.Type = olBCC
End If
' Set the Subject, Body, and Importance of the message.
.Subject = txtSubject
.Body = txtBody & vbCrLf & vbCrLf
.Importance = olImportanceNormal
' Add attachments to the message.
If Len(attachmentfile1) > 2 Then
Set objOutlookAttach = .Attachments.Add(attachmentfile1)
End If
If Len(attachmentfile2) > 2 Then
Set objOutlookAttach = .Attachments.Add(attachmentfile2)
End If
If Len(attachmentfile3) > 2 Then
Set objOutlookAttach = .Attachments.Add(attachmentfile3)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top