By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

How can I 'pause' my code?

P: 167
I am calling a .bat file from my access(2000) program to copy a file and I would like to put a test in the code to check for the existance of the file once the .bat file has finished. I actually am using 'vbhide' on the shell execute option of the .bat file so the Dos window will not show.
Can I somehow put a pause in my program to allow the file enough time to complete the copy before I continue on with the file checking code? I read some info about using an "API" it just seems that there should be a less complicated way to do this.
Any suggestions would be appreciated!!
Jan 21 '09 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 903
Try this procedure from MS. It gives a proper method of checking when a shelled process is completed. It uses the 'createprocess' function instead of the 'shell' function.

How to: Determine When a Shelled Process EndsĀ*[Access 2007 Developer Reference]

Jan 21 '09 #2

Expert 5K+
P: 8,638
  1. Declare the following Sub-Routine in a Standard Code Module:
    Expand|Select|Wrap|Line Numbers
    2. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  2. Copy and Paste, then Execute the following Code replacing strSource and strDestination with your own values:
    Expand|Select|Wrap|Line Numbers
    2. On Error Resume Next
    3. Dim strSource As String
    4. Dim strDestination As String
    5. '
    6. strSource = "C:\Test\Northwind.mdb"
    7. strDestination = "C:\MISC\Northwind.mdb"
    8. '
    9. DoCmd.Hourglass True
    10. '
    11. FileCopy strSource, strDestination
    12. '
    13. 'Delay 3 seconds (Argument is in milliseconds)
    14. Sleep 3000
    15. '
    16. DoCmd.Hourglass False
    17. '
    18. If Dir$(strDestination) <> "" Then
    19.   MsgBox "Copy Operation was a success!", vbExclamation, "File Copied"
    20. Else
    21.   MsgBox "Boo Boo in File Copy Operation!", vbExclamation, "File Not Copied"
    22. End If
Jan 21 '09 #3

Expert Mod 15k+
P: 31,494
Have you seen ShellWait() Function?
Jan 25 '09 #4

Expert 100+
P: 489
You could also do the copy within access using filesystemobject. You will have to enable the referance to microsoft scripting to use this.

Expand|Select|Wrap|Line Numbers
  1. Dim fso
  2. Dim SourceStr as string     'Complete path to source file
  3. Dim DestStr as string       'Complete path to destination file
  5. Set fso = CreateObject("Scripting.FileSystemObject")
  6.     If Not fso.fileExists(SourceStr) Then
  7.         MsgBox "Cannot Find File"
  8.     Else
  9.         fso.CopyFile SourceStr, DestStr
  10.     End If
  11.         Set fso = nothing        
Jan 26 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.