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

Multiple Recordsets

Status
Not open for further replies.

ryan1

Programmer
May 15, 2002
106
US
I'm automating an email and sending to employees. But i need to do this multiple times and my recordset will change about five times pulling from differnet queries. Does anybody know how to run through the current recordset until EOF is reached change the recordset to rst2 then send those emails until EOF is reached, change the recordset to rst3 etc...


Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
dim mydb as database
dim rstas recordset

set mydb = currentdb()
set rst= mydb.openrecordset("Mytable")

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

do until rst= EOF

With objOutlookMsg
.to = rst![Email Address]
.body = "Whatever the message is" & rst!
.send

End With

loop
 
I'm a little curious about your design, why you would need to run to EOF and then use another recordset. You can either,

Dim strSQL
strSQL = CurrentDb.QueryDefs("qryMyQuery").SQL
Set rst1 = CurrentDb.OpenRecordset(strSQL)
Run to end.
strSQL = CurrentDb.QueryDefs("qryMyQuery2").SQL
Set rst1 = CurrentDb.OpenRecordset(strSQL)
Run to end.
strSQL = CurrentDb.QueryDefs("qryGetOutlookNames").SQL
Set rst1 = CurrentDb.OpenRecordset(strSQL)

Of course you can always use OpenRecordset("qryName")

or use multiple recordsets.

----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top