Sending e-mail from Access

D

Doug Shannon

All,

I'm having trouble figuring out this bit of code.
I am be no means sure that it is correct, as I am by no
means a programmer.

What I need it to do is read from a table in the resident
database called "e-mail_feeder" and put portions of each
record into the corresponding places of an e-mail and
then send said e-mail (i.e. I am providing the
recipients, subject and content from the db).


I'm using Office 2003 Professional, the base code came
from a book that may have been intended for Outlook 2000
(not sure right this minute), it was to assign Tasks from
Access data. The limited modifications I have made were
based on info I collected from the M$ Developer site
(mostly intended for Office 97).


I get an undefined variable error where I go to define
the new mail item [Set objMail = objOutlook.CreateItem
(olMailItem)] - it's bouncing "olMailItem" as undefined.


Please help me see where this is going wrong and why.
Any assistance will be appreciated!

Doug

CODE STARTS HERE:
Option Compare Database
Option Explicit

Sub ExportMailToOutlook()

'Export the mail in the schedule Details table of the
'Matrix Industries resources Scheduling database to
Outlook mail

'Declare the Access database
Dim objDB As Object
'Declare the RecordSet
Dim objRecSet As Object
'Open the Database
Set objDB = OpenDatabase("c:\Documents and
Settings\DShannon\My documents\work\rfi_Audit\RFI.mdb")
'Assign the RecordSet
Set objRecSet = objDB.OpenRecordset("e-mail_feeder")

'Declare Outlook object
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
objOutlook = New Application
'Declare the Outlook NameSpace object
Dim objNameSpace As Object
'Declare the Inbox folder as object
Dim objInbox As Object
'Declare an object for a Mail
Dim objMail As Object

'Assign the objNameSpace object
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
'Assign the Inbox folder
Set objInbox = objNameSpace.GetDefaultFolder
(olFolderInbox)

With objRecSet
'Move to the first record
.MoveFirst

'Use Do While loop to repeat for each record
Do While Not .EOF

'Create a new Mail item
Set objMail = objOutlook.CreateItem(olMailItem)

'Assign the Subject to the Mail
objMail.Subject = ![msgSubject]
'Assign the primary recipient to the Mail
objMail.To ![toWho]
'Assign the copied recipients to the Mail
objMail.CC ![copyWho]
'Assign the content/body to the Mail
objMail.Body = ![msgBody]
'Send the Mail
objMail.Send
'Move to the next record
.MoveNext
Loop

End With

objOutlook.Quit
Set objOutlook = Nothing

End Sub
 

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