Running vbs script from Access (1 Viewer)

Harris@Z

Registered User.
Local time
Today, 17:49
Joined
Oct 28, 2019
Messages
84
Hi, hope someone can help!
I trigger a vbs script (update.vbs) when a form closes, which is meant to trigger a batch file (update.bat).
The reason for doing it this way is to keep the process hidden.
I have included text messages in both when testing to ensure that each works.

When I trigger update.vbs itself, it works and triggers update.bat successfully.
However, when update.vbs is triggered when the form closes, it appears to run for the message pops up, but the .bat file is not triggered

I would even be happy to have the update.bat file run on its own, but cannot get this to work.

Can anyone advise?
Thanks, Harris
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:49
Joined
May 7, 2009
Messages
19,249
why vbs then call bat, can you not use Shell to execute the bat?
 

Harris@Z

Registered User.
Local time
Today, 17:49
Joined
Oct 28, 2019
Messages
84
Used these:
Call shell(Environ$("COMSPEC") & " /p H:\My Documents\AccessDatabases\UpdateDB.bat", vbNormalFocus)

Dim RetVal
RetVal = shell("H:\My Documents\AccessDatabases\UpdateDB.bat", 0)

Neither worked
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:49
Joined
May 7, 2009
Messages
19,249
can you copy the .bat to your CurrentProject.Path folder and run it there?
you also need to update the .bat file to fix any Path inside the .bat.
 

Harris@Z

Registered User.
Local time
Today, 17:49
Joined
Oct 28, 2019
Messages
84
The .bat file is in my CurrentProject.Path

I have accidentally found this to work!
shell "cmd /c ""H:\My Documents\AccessDatabases\UpdateDB.bat""", vbNormalFocus

However can you advise on how to change the path using CurrentProject.Path?
I have tried various ways and simply cannot get the .bat to then execute.

Even tried this:
Dim BatName As String
BatName = Chr(34) & Chr(34) & " " & CurrentProject.Path & "\UpdateDB.bat" & Chr(34) & Chr(34)
Debug.Print BatName

shell "cmd /c & BatName & ", vbNormalFocus

Thanks for your help!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:49
Joined
Oct 29, 2018
Messages
21,600
The .bat file is in my CurrentProject.Path

I have accidentally found this to work!
shell "cmd /c ""H:\My Documents\AccessDatabases\UpdateDB.bat""", vbNormalFocus

However can you advise on how to change the path using CurrentProject.Path?
I have tried various ways and simply cannot get the .bat to then execute.

Even tried this:
Dim BatName As String
BatName = Chr(34) & Chr(34) & " " & CurrentProject.Path & "\UpdateDB.bat" & Chr(34) & Chr(34)
Debug.Print BatName

shell "cmd /c & BatName & ", vbNormalFocus

Thanks for your help!
Have you tried?

Code:
batName="cmd /c """ & CurrentProject.Path & "\UpdateDB.bat"""
Shell batName
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:49
Joined
Sep 12, 2006
Messages
15,741
what does the .bat file actually do?

you can't update a database file while you are using it. Maybe the .bat file commands just fail.
 

Harris@Z

Registered User.
Local time
Today, 17:49
Joined
Oct 28, 2019
Messages
84
Excellent, worked like a charm.
Syntax is obviously everything!

Thank you very much for your help. Much appreciated
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:49
Joined
Oct 29, 2018
Messages
21,600
Excellent, worked like a charm.
Syntax is obviously everything!

Thank you very much for your help. Much appreciated
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom