Email From Outlook Template Code Issues (1 Viewer)

JohnPeasley

Registered User.
Local time
Today, 14:44
Joined
Nov 28, 2016
Messages
10
I need to send an outlook template as an email from Access. When I use the code below it hangs up at “CreateItemFromTemplate” and I keeping an error message - “Compile Error: Method or data member not found.”

I have the following references checked: Microsoft Access 14.0 Object Library; Microsoft Outlook 14.0 Object Library; Visual Basic for Applications; OLE Automation; Microsoft Office 14.0 Access Database Engine Object Library; Microsoft Scripting Runtime.

Any help would be greatly appreciated

Private Sub Create_Email_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With Outlook.Application
'Create the message.
Set objOutlookMsg = Application.CreateItemFromTemplate("C:\Documents\templates\Rejects.oft")
.Display
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
 
Last edited:

Minty

AWF VIP
Local time
Today, 19:44
Joined
Jul 26, 2013
Messages
10,366
I think you are effectively referring to the .Application part twice
Code:
With Outlook.[COLOR="Red"]Application[/COLOR]
'Create the message.
Set objOutlookMsg = [COLOR="red"]Application[/COLOR].CreateItemFromTemplate("C:\Documents\t emplates\Rejects.oft")
.Display
End With

Try it without the second Application.
 

JohnPeasley

Registered User.
Local time
Today, 14:44
Joined
Nov 28, 2016
Messages
10
Is this what you meant? It now gives me a runtime error # 438 for .display

Private Sub Create_Email_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With Outlook.Application
'Create the message.
Set objOutlookMsg = CreateItemFromTemplate("C:\Documents\templates\Rejects.oft")
.Display
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
 

JohnPeasley

Registered User.
Local time
Today, 14:44
Joined
Nov 28, 2016
Messages
10
I got it to work - Thank you so much! I've been working on this for over a week and have read so many forum posts trying to find the answer. Good thing the boss didn't know how long I've been on the web lately. :) After your suggestion, I only needed to add objOutlookMsg in to .Display and it correctly brought up the email template.

Private Sub Create_Email_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
'Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With Outlook.Application
'Create the message.
Set objOutlookMsg = CreateItemFromTemplate("C:\Documents\templates\Rejects.oft")
objOutlookMsg.Display
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
 

Users who are viewing this thread

Top Bottom