Looping through records to send emails

Sandpiper

Registered User.
Local time
Today, 20:11
Joined
Feb 21, 2006
Messages
55
Hi
I'm trying to send the contents of a recordset via individual emails to the same person.
I can make this work if I'm attaching a report or if it's just one record, but for some reason I can't get the .movenext to work. The code will even send the correct number of emails, it's just sending the 1st record x number of times instead of looping through, could anyone tell me what i've done wrong.

Ideally this should run when an unrelated form opens, but to try and help myself i've created a form to display the records (it didn't help)!
Thanks very much

Dim rs as recordset
Set rs = currentdb.openRecordset ("qry_EOOM")

rs.movefirst

Docmd.openform "frm_EOOM"

Do until rs.EOF

DoCmd.SendObject acSendNoObject,,,"jo@****.co.uk",,,"Record " & [me.EOOMID] & " Needs Updating", "EOOM ID: " & [EOOM] & vbnewline & vbNewline & ..........

rs.movenext

Loop

Docmd.Close "frm_EOOM"
 
When you make assuptions, and code does not do what desired, then the first thing to do is to check the assumptions.

You think .movenext does not do its job. Did you check that? See http://www.access-programmers.co.uk/forums/showthread.php?t=149429 , the section how to debug VBA code and below.


The code does what you told it to do.

Check this line

DoCmd.SendObject acSendNoObject,,,"jo@****.co.uk",,,"Record " & [me.EOOMID] & " Needs Updating", "EOOM ID: " & [EOOM] & vbnewline &
You tell it to send data concerning EOMID in your current form, and that does not change when you step through the recordset.

If you need data from you recordset then

SomeValue= rs!NameOfSomeValue
 
Thanks very much for the reply.
I've tried the debugging and although I understand what you are saying, I'm being very thick and am still getting it wrong.

I've put my reference to the EOOMID = rs!EOOMID in, but now i'm getting an error message that the Recordset is not updateable.

As you can guess, i'm not a great coder, so could you please tell me where I should be putting this code

Thanks
 
Ignore my last message. Brain kicked back into gear and i've got the code in the right place.
Thanks for your help
 

Users who are viewing this thread

Back
Top Bottom