Running Copy Command in background

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok, from reading all through Google, I know you can't run VBA in the
background while other code runs, so I need some help with the direction to
go for a workaround. I have a system that automatically will update the
"front end's" of my database whenever it is outdated and the user logs in.

The process works basically. I have code that when it detects an older
version, it will open another database, and shut down the active one. With
this other database, first it will delete the current front end, then it will
go to the computer where the backend is stored (as well as the new front end,
in a specific location). It takes the new front end using:

FileCopy SourceFile, DestFile

It copies the new front end into where the old front end was.

All this works, but I am trying to use the timer ever on the form to make a
progress bar so the user knows how much time is left, I do this by checking
the file size of the new front end and then based on a basic transfer rate, I
calculate time.

The obvious problem is that as soon as the cody starts the copy and paste,
it hangs there and the form timer doesn't go. So the countdown of time
remaining doesn't work. As soon as the file is completly copied, the time
goes straight to 0 and the program finishes. When an update can take 15
minutes, I would really like to let people know how much time they have left.

I realize this is a problem, and I am willing to do the work to make
something that will work, I just don't have the slightest idea which way to
start. I could really use some help just getting moved forward on this one.


Thanks,
James Stephens
 
Hi James,

There's no built-in support for this in VB/A. The Windows API provides
it in the CopyFileEx() function, which takes a callback function as an
argument and calls it every time it copies a chunk of a file. There's a
description and VB code sample (including a CopyProgressRoutine()
callback function) in the API guide at www.allapi.net.

If that's too frightening you can fake it in VBA by using the Open
statement to open the two files, and Get and Put or some such to read
and write a chunk at a time till you get to the end, updating progress
and calling DoEvents each time round the loop.
 
I was able to make the API stuff work (which is new for me). Thanks for the
help on that, it will make keeping my database up to date much easier.
 
Back
Top