Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset for Email

Status
Not open for further replies.

McFestoe

Technical User
Dec 16, 2003
145
GB
Could somebody have a look at the below code, can only get the code to email one customer, also is thee a way of forcing outlook to use a email address that you specify instead of grabbing the default sending address.

Private Sub Email_Click()

Dim db As Database
Dim rs As DAO.Recordset
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Email FROM Cust")

Do Until rs.EOF
On Error GoTo ErrorHandler

With objEmail
.To = rs!Email
.Subject = "Appointment Required "
.HTMLBody = "The system we installed at your premises is due for a service please can<br>you contact us to arrange a suitable time<br><br>"

.Send
End With
ErrorHandler:

Resume Next

rs.MoveNext

Loop

End Sub
 
McFestoe,

I think the problem is the location of this line.

Code:
Set objEmail = objOutlook.CreateItem(olMailItem)

Move the line inside the Do Until Loop

Code:
Do Until rs.EOF
On Error GoTo ErrorHandler

[COLOR=green]Set objEmail = objOutlook.CreateItem(olMailItem)[/color]


With objEmail
  .To = rs!Email
  .Subject = "Appointment Required "


Good luck
 
Jedraw,

Many thanks you where right, something i could not see. Just tried it and getting the outlook security message for every email sent will have to do some more reading up.
 
Do a google search for outlook object model guard

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top