make function wait

R

RayV

I have a Macro that:
runs a function that:
runs a bat file that:
runs an ftp script that:
creates a txt file of the ftp sites directory

This runs fine except the next step in the macro is to import the text
file using TransferText. Access attempts to import the txt file
before the ftp script finishes writing it and I get:
"Microsoft Jet database engine could not find..."

I have tried:
putting a pause in the bat file - Access keeps going not wating for
the bat file to finish
putting the TransferText as the next step in the function - same error
"could not find"
having the first macro run a second macro with the TransferText - same
error

How can I make either the function or the macro wait until the file
exists or is available?
 
K

Kerry

I have a Macro that:
runs a function that:
runs a bat file that:
runs an ftp script that:
creates a txt file of the ftp sites directory

This runs fine except the next step in the macro is to import the text
file using TransferText. Access attempts to import the txt file
before the ftp script finishes writing it and I get:
"Microsoft Jet database engine could not find..."

I have tried:
putting a pause in the bat file - Access keeps going not wating for
the bat file to finish
putting the TransferText as the next step in the function - same error
"could not find"
having the first macro run a second macro with the TransferText - same
error

How can I make either the function or the macro wait until the file
exists or is available?

You can use the Dir function to see if the file exists before trying
to import it.

You can wait using the Sleep API.
 
R

RayV

You can use the Dir function to see if the file exists before trying
to import it.

You can wait using the Sleep API.- Hide quoted text -

- Show quoted text -

I have found that if the timing is right (or should I say wrong) the
ftp script begins writing the file while access is trying to import it
then I get unable to open file error 3051': The Microsoft Jet database
engine cannot open the file C:\file.txt. It is already opened
exclusively by another user or you need permission to view its data.

maybe a dir first then error trap 3051?
 
D

Dennis

I'd error trap it with a loop, a 5 second "sleep", and a counter that would
only sleep for 10 tries or so and then error out.
 
G

George Nicholson

Maybe add a command to your script to create a 2nd, dummy file, then use
Dir() to see if the dummy file has been created. The idea being the 2nd file
won't exist until the 1st file is completed. Once the 2nd file comes into
existance your code can proceed.

(don't forget to delete the dummy file)
 
R

RayV

Maybe add a command to your script to create a 2nd, dummy file, then use
Dir() to see if the dummy file has been created. The idea being the 2nd file
won't exist until the 1st file is completed. Once the 2nd file comes into
existance your code can proceed.

(don't forget to delete the dummy file)
--
HTH,
George








- Show quoted text -

Thanks all.

I got it working with a do-while loop that checked that the file
existed using Dir and error trapped 3051 to resume until the file is
completely written.
Not pretty, but it a one-user app (me) so I'll know if it is having
problems. I just wanted the process automated since there are several
files.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top