Attach a document to an e-mail through code (1 Viewer)

adz2013

Registered User.
Local time
Today, 06:18
Joined
Dec 13, 2001
Messages
64
Does anyone know how to attach a word document to a e-mail from a database through code. I have a list of clients in a database with their e-mail addresses and I need to send an e-mail to them with a attachment. There are about 1000 clients that need this e-mail.


Any help would be appreciated!:confused:
 

Nero

Shop smart, shop S-Mart
Local time
Today, 06:18
Joined
Jan 8, 2002
Messages
217
Create a module and insert this code.
Public Function MailNot()

Dim olkapps As Outlook.Application
Dim olknamespaces As Outlook.NameSpace
Dim objmailitems As Outlook.MailItem

Set olkapps = New Outlook.Application
Set olknamespaces = GetNamespace("MAPI")
Set objmailitems = olkapps.CreateItem(olMailItem)
With objmailitems
.To = NameRef
.Subject = "Subject Title"
.Body = "Text In Here"
.Importance = olImportanceHigh
.Attachments = "C:\Your File"
.Send


End With

Set objmailitems = Nothing
Set olknamespaces = Nothing
Set olkapps = Nothing

End Function

Then on your button that you want to use to send your emails put this code
Private Sub SendMail()
On Error GoTo Mailerr

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim MyDate As Date
Dim Msg

Set db = CurrentDb
Set rst = db.OpenRecordset("Your Table")


rst.MoveFirst

Do Until rst.EOF = True

NameRef = rst.Fields("Mail Name")
MailNot.MailNot
rst.MoveNext

Loop

Set rst = Nothing
Set db = Nothing

Mailend:
Exit Sub
Mailerr:
MsgBox Err.Description
Resume Mailend

End Sub

I haven't tested this but it should get you somewhere near.
Post back if you have problems.

Kev
 
Last edited:

Users who are viewing this thread

Top Bottom