View Full Version : VB Script Help!


ejstefl
10-17-2006, 08:13 AM
Hello All,

I have a script that I use to copy an updated front end from a server to the user's local PC. The script runs when the old front end is opened and detects a new version on the server. The front end closes and calls the script.

All works well UNLESS the front end compacts on close. In that case, I get an error indicated that the old front end cannot be delted (presumably because it is already "open").

How can I modify the script to wait until the front end is done compacting before trying to replace it? Any help is appreciated!

Dim strOldPath
Dim strNewPath
Dim FSO

strOldPath=left(wscript.scriptfullname,len(wscript .scriptfullname)-len(wscript.scriptname)) & "dbname.mdb"
strNewPath ="\\server\dbname.mdb"

Set FSO = CreateObject("Scripting.FileSystemObject")

do while FSO.FileExists(Left(strOldPath, len(strOldPath)-3) & "ldb")=True
'As long as an ldb file exists, someone is in the database, so just do nothing until it goes.
loop
'Set WshShell = WScript.CreateObject("WScript.Shell")

FSO.CopyFile strNewpath,strOldPath,True

'wshshell.run stroldpath
msgbox "The newer version has been installed. You may now open the database.", vbinformation, "Database updated."

RuralGuy
10-17-2006, 08:22 AM
Maybe this link (http://www.mvps.org/access/api/api0004.htm) will help.

ejstefl
10-17-2006, 08:44 AM
Thanks for the link! Maybe I'm not thinking about this correctly, but I'm not sure how that helps.

My problem is that I close access, and then call the VB Script file. The problem is that if Access is still compacting, the VB Script file won't work.

The attached code will execute an external app, and then wait for it to finish before running the next line of code in Access.

I'm not sure how I can adapt the linked code to help me?

RuralGuy
10-17-2006, 08:54 AM
I don't have a good answer for you, sorry.

Rickster57
10-17-2006, 09:07 AM
This suggestion probably doesn't solve your problem but what if after your dim statements in your vbscript you had it wait, say 30 or 60 seconds, before firing off the vb script that does the replace. Like using something like sleep 60 or in vb.net system.threading.thread.sleep(30000)