0

My VBA code in Access is trying to write cmd lines in and run a batch file, which executes some R lines to create a txt file, before a webbrowser control on an Access form updates its ControlSource wth this newly created txt file.

dim FileNumber as int
dim isDone as variant

' write in and create a batch file
  FileNumber = FreeFile  
  Print #FileNumber, "cmd to run R lines..."
  Close #FileNumber

 'run batch file
  isDone = Shell("D:\path\BatchFile.bat", vbNormalFocus)

 'update webbrowser control source
  Me.WebB63.ControlSource = "=""D:\path\TextFile.txt"""

The problem is my VBA codes continues to run before the cmd lines in the batch file are fully executed. So the webbrowser is already looking for the txt file before it is actually created and gives this error becuase it couldn't find the txt file. enter image description here

How can I code so the the batch file is fully executed and txt is created before updating webbrowser control source?

Thanks

braX
  • 11,506
  • 5
  • 20
  • 33
davidzxc574
  • 471
  • 1
  • 8
  • 21
  • [Shell](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-function) runs asynchronously. See https://stackoverflow.com/questions/8902022/wait-for-shell-to-finish-then-format-cells-synchronously-execute-a-command for a solution. – Vincent G Jan 11 '19 at 08:13
  • Thanks. Problem solved – davidzxc574 Jan 11 '19 at 09:15

0 Answers0