Wrox Programmer Forums
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 25th, 2006, 12:08 PM
Registered User
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Outlook Automation in Access

Hi there, I am new to VB and am trying to execute the VBA in Chapter 10, however I receive a runtime error stating the module used in this statement cannot be found:

 Set objEmail = objOutlook.CreateItem(olMail)

I've set my references to use MS Outlook library so I don't know what the issue could be. Does anyone have any idea?

Here's the script :

Sub ControlOutlook()

Dim objOutlook As New Outlook.Application
Dim objEmail As Outlook.MailItem

Dim strLtrContent As String
Dim rsContacts As New ADODB.Recordset

rsContacts.ActiveConnection = CurrentProject.Connection
rsContacts.Open "tblContacts"

'for each record in the tblContacts table, send an email
Do While Not rsContacts.EOF

   strLtrContent = "Dear " & rsContacts("FirstName") & " "
   strLtrContent = strLtrContent & rsContacts("LastName") & ":" & vbCrLf & vbCrLf
   strLtrContent = strLtrContent & "Please note we have moved to a new location. "
   strLtrContent = strLtrContent & "Our new address is 4 Somewhere, Avon, IN 46060."
   strLtrContent = strLtrContent & vbCrLf & vbCrLf & "Sincerely," & vbCrLf & vbCrLf
   strLtrContent = strLtrContent & "Your Favorite Store"

   'create an email regarding the new business location
   Set objEmail = objOutlook.CreateItem(olMail)
   objEmail.Recipients.Add rsContacts("Email")
   objEmail.Subject = "Our address has changed."
   objEmail.Body = strLtrContent

   'send the message

   'move to the next contacts record

End Sub

Old June 27th, 2006, 07:00 PM
Authorized User
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts

Try: Set objEmail = objOutlook.CreateItem(olMailItem)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook '03 automation from Access '03 error Derek_05 Access VBA 2 February 3rd, 2006 06:09 AM
Automation with Access and Excel venomm Access 2 March 20th, 2005 11:34 AM
Outlook Automation Error www2004 Pro VB 6 4 August 12th, 2004 09:09 AM
Access automation william.murray BOOK: Access 2003 VBA Programmer's Reference 3 July 30th, 2004 07:59 AM
Outlook 2000 Automation byron Pro VB 6 4 July 10th, 2003 01:10 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.