Avatar of Andy Brown
Andy Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Ensuring all processes are complete before continuing

I am writing a function via MS-Access VBA that generates several files and stores them in a folder (PDF, XLSX etc).  It then creates an email and attaches all of the files within the specified folder (I am using EASendMail to do this).  On my PC it works just fine, but I'm a little concerned that on a slower PC/network, Access (or the PC itself) may still be creating the files (XLS, PDF etc.) when the command to attach all of the files is issued (jumping ahead of itself).

Ideally, I'd like someone to come back to me and say that Access will not start work on the email/attach function until the previous processes have all finished, or before issuing the "oSmtp.AddAttachments" command, you should do x to ensure everything has been done.

I know I could check that the files in the folder exist before attaching (but if I don't have to do this, I'd rather not).
Microsoft ExcelMicrosoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
crystal (strive4peace) - Microsoft MVP, Access

You can use a Transaction.  You can manage transaction processing during a session defined by a DBEngine  Workspace object -- for instance: start (BeginTrans), Rollback, and commit (CommitTrans)

here is a help page:
https://msdn.microsoft.com/en-us/library/office/ff835327(v=office.15).aspx
Andy Brown

ASKER
Thank you - That's a good idea, but I'm not too sure how to implement it (as I'm not writing data as such).  

Ideally, it will be something like

Transaction begin
Create files
When files are actually sitting in the folder and everything is done
Transaction ends
Attach files from folder
crystal (strive4peace) - Microsoft MVP, Access

you're welcome

here is a help page for CreateWorkspace -- but I don't think you need to do that as there is a default workspace
https://msdn.microsoft.com/en-us/library/office/ff821374(v=office.15).aspx

btw, currentdb is like DBEngine(0)(0) -- just that currentdb is a pointer so more up-to-date when it is initialized

I think you can simply do something like this:
Set myDb = DBEngine.OpenDatabase(sName)
https://msdn.microsoft.com/en-us/library/office/ff193474.aspx

use db.execute

then either
DBEngine.CommitTrans
or
DBEngine.Rollback
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Gustav Brock

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.
Andy Brown

ASKER
Thanks Gustav - I'll start writing the code......
Gustav Brock

You may be able to use the Sleep function here:

Modern/Metro style message box and input box for Microsoft Access 2013

Go to paragraph Simulating dialogue mode for code for a reliable loop that doesn't kill the machine.

/gustav