VBA Security

G

Guest

Since switching to 2007 I am having no end of trouble with the running of my
code. The latest is a piece designed to create an email.

Sub SendEmail(strExcelFile, strEmailAddress)
Dim myItem As Outlook.MailItem
Dim myRecipient As Outlook.Recipient

Set myItem = Application.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add(strEmailAddress)
.....

The software is telling me it doesn't recognise CreateItem. The references
are correct and in place yet the keyword CreateItem is gone. This used to
work in 2003. I've put the database in a trusted location but it is still
playing games. What's going on here?


What am I missing?

H
 
D

Douglas J. Steele

All you've got is Application.CreateItem. To Access, "Application" is
Access, which cannot create mail items. You would appear to be missing
instantiating the Outlook application:

Sub SendEmail(strExcelFile, strEmailAddress)
Dim objOutlook As Outlook.Application
Dim myItem As Outlook.MailItem
Dim myRecipient As Outlook.Recipient

Set objOutlook = New Outlook.Application
Set myItem = objOutlook.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add(strEmailAddress)
 

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