PDA

View Full Version : VBA: wait for object to finish not working properly



maikusama
08-21-2015, 03:23 PM
Sub rununzipandMove()
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.Run "cmd.exe /c ""c:\temp\test.bat"", windowStyle, waitOnReturn"
Call importintoAccess
End Sub


Sub importintoAccess()
Dim runAccess As Object
Set runAccess = CreateObject("Access.Application")
Call runAccess.openCurrentDatabase("C:\Temp\CLM.accdb")
runAccess.Visible = True
runAccess.DoCmd.RunMacro "Import"
End Sub



When I run this code, it should run the CMD batch file, then once that has completed make the call to run the Access file. But it's calling the access right away as soon as the batch file opens.. What am I doing wrong?

mancubus
08-22-2015, 08:31 AM
i have no idea but found this:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=971

snb
08-22-2015, 08:49 AM
Sub M_snb
x0=CreateObject("wscript.shell").Run("cmd.exe /c C:\temp\test.bat")

with CreateObject("Access.Application")
.openCurrentDatabase("C:\Temp\CLM.accdb")
.Visible = True
.DoCmd.RunMacro "Import"
end with
End Sub