file copy problem

Hi Gurus,

Following is a part of my application:

Dim retval
retval = Shell("c:\cos\copyTable.bat", vbHide)
DoEvents
adcTempTable.RecordSource = "Select * from TempTable"
adcTempTable.Refresh

The batch file copies the access database from a network drive to the local disk and the TempTable is a table in the database. I get this error when I run the program.

"TempTable - cannot open database ". It may not be a database that your application recognizes, or the file may be corrupt."

My guess is that the database is read even before it is completely copied - hence the error.

On the other hand, if I add some junk code like

For i = 1 to 10000000 'a very large nr
x = Sqr(i)
next i

after doevents line, I don't get the error. Kindly advice.

Tia,

Arun
[879 byte] By [nmarun] at [2007-11-17 17:10:10]
# 1 Re: file copy problem
Shell("c:\cos\copyTable.bat", vbHide)

the shell runs programs asyncronously. That means, you go on executing your code while table is being copied.
If you had a visible window, you could use the waitforsingleobject api in conjunction with the openprocess to make it wait. As you hided Dos window, I think you should map the remote drive, use Fso to copy the file syncronously, then go on with the rest of code
Cimperiali at 2007-11-10 0:22:40 >
# 2 Re: file copy problem
Yes the shell command don't wait for the end of the command but return immediatly and you code continue execution while your command is being executed.

Maybe you could do something like that :
This should loop until it can open the file but watch out for Infinite Loops

Dim iFile as Integer
iFile = FreeFile

ErrorOpen:
DoEvents
On Error goto ErrorOpen
Open "TempTable" for access write as #iFile
Close #iFile
On Error Goto 0

Heulsay
Heulsay at 2007-11-10 0:23:37 >
# 3 Re: file copy problem
Or you could use the COPYFILE() API to copy the file for you. This is a sync function which means it will not return until the file has been copied or an error occurred.

-Cool Bizs
coolbiz at 2007-11-10 0:24:33 >