I finally got this to work!
Wayne's suggestion of moving the code from the sub form "Current" event to the buttons "Click" event was very helpful and got me on the right path.
I had a bit of an issue with how to get the loop to go to the next record, but this is what I ended up with after searching a bit more:
Private Sub SchedEmailButton_Click() Dim rst As Object 'DAO.Recordset <-- For some reason unknown to me the code didn't like declaring as a "DAO.Recordset" Set rst = Me.FacEmailingList2.Form.Recordset With rst .MoveFirst Do While Not .EOF SchedEmail .MoveNext Loop End With Set rst = Nothing
These didn't work to move to the next record (I don't know why):
RunCommand acCmdRecordsGoToNext DoCmd.GoToRecord record:=acNext DoCmd.GoToRecord , , acNext
manpreet
Best Answer
2 years ago
I have a split multi-user MS Access (2013 ACCDE file) database that is used to email out class schedules and syllabi to professors. The end user presses a button on a form when they are ready to send emails and then the DB has code that cycles through each entry (about 70) in a filtered datasheet within a subform. Generally, the code to add attachments and to send email works... However, with how the code is set below, the last person on the email list gets emailed twice... they are both the first and the last person the DB sends an email to...
I've included my pertinent code below. As always I'm greatly appreciative of any assistance you can offer.
Alternatively, I've tried this as well for the button, which is when only the first record gets skipped (Thus my post title):
This is the code that loops through the list of email recipients, stripped down (edited) to really what matters due to its length:
[EDIT]This is the full code (just in case):
[EDIT]
Here's what the button code looks like now. Because I'm referencing a subform everything seems to be messed up with how the references are made:
Here's the basic changes I've made to the email loop (I've made it it's own procedure, this is more for reference than anything):