Creating outlook message from template

J

John

Hi

I am using the below code to generate an outlook message from a template
from within access. I am getting the 'Object variable or With block variable
not set' error on the line indicated. What am I doing wrong?

Thanks

Regards

Dim OutlookApp As New Outlook.Application
Dim em As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient

em = OutlookApp.CreateItemFromTemplate(Template) '<== This line gives the
error.

With em
em.Recipients.Add ("(e-mail address removed)")
em.Recipients.Add ("(e-mail address removed)")
.Subject = "My Subject"
.Body = "Body Text"
.AttachmentAdd "c:\fiewlname.txt"
.Display (False)
End With

Set em = Nothing
 
6

'69 Camaro

Hi, John.
I am getting the 'Object variable or With block variable
not set' error on the line indicated. What am I doing wrong?

Since "em" is an object variable that has not been declared as "New," the
syntax must use the "Set" keyword. For example:

Set em = OutlookApp.CreateItemFromTemplate(Template)

The variable named "Template" is neither declared nor initialized in the
code you posted. Perhaps it is passed as a parameter from the calling
procedure. Wherever it is, ensure that the variable's string includes the
complete path and file name of the template file.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
 

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

Top