Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Ensuring all processes are complete before continuing

Posted on 2016-10-21
6
Medium Priority
?
66 Views
Last Modified: 2016-10-21
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).
0
Comment
Question by:Andy Brown
  • 2
  • 2
  • 2
6 Comments
 
LVL 22
ID: 41853895
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
1
 

Author Comment

by:Andy Brown
ID: 41853900
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
0
 
LVL 22
ID: 41853933
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Accepted Solution

by:
Gustav Brock earned 2000 total points
ID: 41854048
Transaction control has nothing to do with this. It only controls updates to the database, totally unrelated to external files.

Your only option is to keep track of the files in a loop, then proceed.

/gustav
0
 

Author Closing Comment

by:Andy Brown
ID: 41854055
Thanks Gustav - I'll start writing the code......
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 41854067
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question