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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop through email addresses to send 1 email to all help in vb code

Status
Not open for further replies.
Dec 5, 2005
40
0
0
US
I found some code and now I'm trying to troubleshoot it.

I have 2 issues.

the line with the ~~~~'s errors out and highlights the entire code to the end of the ~~~~'s

The second question I have is that I have placed this in a module, how do I call the module from the form when a button is placed?

Any help is greatly appreciated. Using Access 2003


Option Compare Database

Dim rsMsgInfo As DAO.Recordset
Dim objOutlookMsg As Object

~~~~rsMsgInfo = dgengine.OpenRecordset("SELECT emailer_currentcampaign.email FROM emailer_currentcampaign,dbOpenDynamic")~~~~


objOutlookMsg = objOutlook.CreateItem(olMailItem)

Do Until rsMsgInfo.EOF
With objOutlookMsg
.To = rsMsgInfo.Fields("EmailAddress")
.Body = "Dear " & rsMsgInfo.Fields("FirstName")
.Subject = "SOME SUBJECT:"
.Send
rsMsgInfo.MoveNext
Loop

rsMsgInfo.Close
 
In your module you need to create the routine. Then from your button "Call" your routine. Below is a routine that will (when you use YOUR table and field names) loop through the recordset. On your command button you could-- Call Loop_Thru_Recordset.


Sub Loop_Thru_RecordSet()

Dim rsMsgInfo As DAO.Recordset
Dim MailAddr As String
'~~~~rsMsgInfo = dgengine.OpenRecordset("SELECT emailer_currentcampaign.email FROM emailer_currentcampaign,dbOpenDynamic")~~~~
Set rsMsgInfo = DBEngine(0).Databases(0).OpenRecordset("SELECT EMAIL FROM tblEmailAddr", dbOpenDynaset)


If rsMsgInfo.RecordCount > 0 Then
rsMsgInfo.MoveFirst

Do Until rsMsgInfo.EOF
MailAddr = rsMsgInfo!EMAIL
rsMsgInfo.MoveNext
Loop
End If
rsMsgInfo.Close

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top