VBA Security

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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)
 
Back
Top