ACCESS creation of a .vbs script to close and reopen an access file

Copper Contributor

I need to manage the code on an external access file that acts as a control of the lock situation verified on the main file which must then be closed and reopened

from Db A I close and reopen the Db B.

Ecco il codice

Private Sub chiude_apre_Click()

' ---> Chiude il file Ship.accdb e lo riavvia

If Dir(Application.CurrentProject.Path & "\Chiudi e riavvia.vbs") = "" Then

Open Application.CurrentProject.Path & "\Chiudi e riavvia.vbs" For Output As #1

Print #1, "Dim shell"

Print #1, "Set shell = wscript.CreateObject(""Wscript.Shell"")"

Print #1, "shell.run ""taskkill /fi """"WINDOWTITLE eq Access - Ship*"""""""

Print #1, "shell.run """"""" & "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE"""" """"" & Application.CurrentProject.Path & _

"\Ship.accdb"""""""

Print #1, "set shell = nothing"

Close #1

End If

Call shell("WScript.exe """ & Application.CurrentProject.Path & "\Chiudi e riavvia.vbs", vbHide)

End Sub

 

It opens the DB B file for me but doesn't close it

the line that should close the file is:

Print #1, "shell.run ""taskkill /fi """"WINDOWTITLE eq Access - Ship*"""""""

 

Someone can tell me where I'm wrong

Thanks for your answers

 

 

1 Reply
It appears you are trying to kill the Ship.accdb file before it's opened. Should the order of these two lines be swapped? Or is the DB A file also called Ship?

Print #1, "shell.run ""taskkill /fi """"WINDOWTITLE eq Access - Ship*"""""""

Print #1, "shell.run """"""" & "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE"""" """"" & Application.CurrentProject.Path & _
"\Ship.accdb"""""""