Avatar of Mac M
Mac M
Flag for United States of America asked on

Access Macro / VBA Question

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
VB ScriptMicrosoft Access

Avatar of undefined
Last Comment
Mac M

8/22/2022 - Mon
Randy Downs

You could put the email code in a while - wend loop.


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. 

Open in new window

ASKER CERTIFIED SOLUTION
John Tsioumpris

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Scott McDaniel (EE MVE )

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy