This is with Access 97. I am trying to use Jetcomp to compact a separate database from the one executing the code.
Somehow the flow of my code is continuing when it should not. Consequently, a file is still locked when the next command tries to delete it. I get a Permission Denied error and the code breaks with the debugger at the offending line. After a few seconds, I click the continue button. Same thing happens. I wait a few more seconds. I click the continue button and it proceeds as it should.
As you can see below, I can get it to work using "Sleep", but that is inelegant and requires me to guess how long it's going to take to be ready.
So how do I prevent the second command from executing until the first command is truly done and all the file locks or whatever are freed up?
Here is the code:
Code:
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Function test()
Name "J:\newco.mdb" As "j:\newco_temp.mdb"
SysCmd acSysCmdSetStatus, "Compacting newco..."
1 Shell "J:\jetcomp.exe -src:" & "j:\newco_temp.mdb" & " -dest:""J:\newco.mdb"" -v3"
If Dir("J:\newco.mdb") = "" Then
SysCmd acSysCmdSetStatus, "Jetcomp failed"
Name "j:\newco_temp.mdb" As "J:\newco.mdb"
Else
SysCmd acSysCmdSetStatus, "Sleeping..."
Sleep 2000
2 Kill "J:\newco_temp.mdb"
End If
SysCmd acSysCmdSetStatus, "Success."
End Function