I am running a batch file from MSAccess in VBA. It is not fully executing. It works just fine if I run it outside of access. I am using VBA to create the bat file and then running it and quitting access. The bat file will then delete the access file and then download a new file and open the new one. Like I said when I run the bat file outside of access it works perfectly. But from access it deletes the current file and then never continues on with the rest of the script. Any guidance would be welcomed.
Code In Access:
Private Sub UpdateFrontEnd(ByVal LocalFilePath As String)
Dim BatchFile As String
Dim Restart As String
Dim ShellCommand As String
BatchFile = CurrentProject.Path & "updater.bat"
Restart = """" & LocalFilePath & """"
ShellCommand = "Invoke-WebRequest http://downloadipaddress/filename.accdb -OutFile filename.accdb"
Open BatchFile For Output As #1
Print #1, "@Echo Off"
Print #1, "ECHO Deleting old file..."
Print #1, ""
Print #1, "ping 127.0.0.1 -n 5 -w 1000 > nul"
Print #1, ""
Print #1, "Del """ & LocalFilePath & """"
Print #1, ""
Print #1, "ECHO Downloading new file..."
Print #1, "powershell -Command " & ShellCommand; ""
Print #1, ""
Print #1, "ECHO Starting Microsoft Access..."
Print #1, "START /I " & """MSAccess.exe"" " & Restart
Close #1
Shell BatchFile
DoCmd.Quit
End Sub
I have tired splitting it into 2 differeant bat files and calling the second from the first but still same result.
I also tried just running the bat and not creating it in the VBA code but still same result.
Evan Terrell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.