run a block of code for multiple records

D

Dan

Is there an easy way to run a block of code for every item in a list box.
Something like the print report. Your can print every report that you want
using by editing the number of records throught the where condition.

If not how would you do it?

Would you do a while loop and have it go to a record and then run the code
and then go to the next record and run the code and so on. I want it to send
an email to everyone in the list box by using outlook.
 
N

Nikos Yannacopoulos

Dan,

You code could look something like:

Dim v_To As String
For i = 0 To Me.List0.ListCount - 1
v_To = vTo & Me.List0.ItemData(i) & ";"
Next
v_To = Left(v_To, Len(v_To) - 1)
DoCmd.SendObject acSendReport, "abc", , v_To, , , _
"Subject XXX", "Message Text YYY"

Where I have assumed the listbox name to be List0; change to the actual
name. The code above loops through the listbox entries and constructs a
recipients list in variable v_To, separated with semi-colons (;), and
then sends a report(?) to all recipients.

HTH,
Nikos
 
Top