Send email using MSOutlook2002

  • Thread starter Thread starter Luiz Gustavo
  • Start date Start date
L

Luiz Gustavo

hi all, I have a database with a table named tb_esw which has three fields:
ieName, iecompany and ieemail. I want to send an email to each member of
this table separately, attaching and word file. How can I do that?

Thanks in advance

gustavo
 
Luiz,

Here is some code that will show you how to do this.

Private Sub btnEmail_Click()
On Error GoTo Err_btnEmail_Click

Dim g_db as Database
Dim g_rs as DAO.Recordset
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem

Set oApp = New Outlook.Application

Set g_db = CurrentDb
Set g_rs = g_db.OpenRecordset("tb_esw", dbOpenSnapshot)

g_rs.MoveLast
g_rs.MoveFirst
Do While Not g_rs.EOF
Set objNewMail = oApp.CreateItem(olMailItem)
With objNewMail
.To = g_rs!ieemail
.Subject = "Put your subject here"
.Body = "Put your message here"
.Attachments.Add "Put your file name here"
.Save
.Send
End With
g_rs.MoveNext
Loop
MsgBox "Finished sending emails!"

Set oApp=Nothing

g_rs.close
set g_rs=Nothing

Exit_btnEmail_Click:
Exit Sub

Err_btnEmail_Click:
MsgBox Err.Description
Resume Exit_btnEmail_Click

End Sub


In addition, a wealth of information about automating Outlook can be found
at:
http://www.slipstick.com
 
OK!! Very good code, but I think I have any problem with a dll, when start
the event (click button) I've got a message saying that there is a *.dll
problem. I'm referring the MSOutlook 10 Object Library. Is there anything
wrong?

Thanks in advance!
 
Luiz,

Please post the complete error message, including the name of the DLL -
there are a lot of DLLs that one can have a problem with!
Also, it would be helpful to know which line of code is causing the failure.
 
Back
Top