I have a Email macro which I converted to VB in Access 2016. When you click the Email button for each record the macro attaches the detail spreadsheet and email the client. I have to click this email button a total of 550 times or more for each client records...My form has two parts to it...I click on each Payee record to pull the details form up and then I click on the Email Detail button to email the client with their attached detail pay spreadsheet. I would like the Email button to loop through each record and perform the task without having to manually go through each record until EOF but I'm unsure how and where to place this in my macro or code...Any help with this would be greatly appreciated...Thanks in advance...See the sample files below... Sample_Code.txt Email_Macro.png
The code below just prints out 20 when it's done. Your code would go in the while section and assumes you know the number of client records (550+). If you have the clients in a table it should be easy enough to determine the number.
If you need to count records of the client maybe try DCount to return the number of records and let that be your end(i.e., replace the 20 in the sample code).
Dim Counter Counter = 0 ' Initialize variable. While Counter < 20 ' Test value of Counter. Counter = Counter + 1 ' Increment Counter. Wend ' End While loop when Counter > 19. Debug.Print Counter ' Prints 20 in the Immediate window.
Note that running Sendobject in a loop has been known to hang with longer running processes. You'd be much better off automating your email client to do this instead of using SendObject. You can't do that with a macro, however. You'd have to use VBA.
Mac M
ASKER
I'm using John's solution and working with him to simply my efforts...Thanks
The code below just prints out 20 when it's done. Your code would go in the while section and assumes you know the number of client records (550+). If you have the clients in a table it should be easy enough to determine the number.
If you need to count records of the client maybe try DCount to return the number of records and let that be your end(i.e., replace the 20 in the sample code).
Open in new window