- Local time
- Today, 08:53
- Mar 14, 2017
Sorry, but I don't really understand what you mean about the Form "not opening". I thought you already had a working Access database and forms opened and worked fine. Not familiar with the code you're using. My advice would be to skip all the fancy event-driven ways to initiate the VBS and rather just call it in an extremely simple way, like "Shell "wscript " & strScriptPath, vbNormalFocus" (one line of code), when the database first opens. Then add some conditional stuff to the VBS loop to test and see if a certain form is loaded or not - whenever it is, act on it. Run it continuously.Sorry, Isaac. I was testing your solution in the time gaps during the workday with lots of distractions. When writing the post #55 I was under wrong impression that the code worked if called from the VBS but not if from the VBA. The code is not working regardels if it is called from the VBS or from the VBA. Therefore, please discard the post #55.
If on open, load, resize, activate, current, the form does not open.
Open event - form doesn't open at all. Have to reset the code (hitting the square buton in the VBA of the form) to reclame control of the access.
Load event - the form opens only after I reset the code. After reset, the form opens and runs the code well.
Resize event - the same as on Load event, only all happens quicker.
Activate - when Pop up and Modal are "yes", the form opens but the code doesn't run. When Pop and modal are set to "no", the form acts the same as in case of Load or Resize.
Current - the same as on Load..., but canceling the code is messier.
The above is for the VBS. The loop never runs if called from the VBA in cases of open, load... If the code is called from the VBA, the form opens after reset, but the loop doesn't run.
If the code is called any other way (button click, mouse move...) it works perfectly. That is for both VBA and VBS.
To start the VBS I use:
Option Compare Database Option Explicit Const PROCESS_QUERY_INFORMATION = &H400 Const SYNCHRONIZE = &H100000 Const INFINITE = &HFFFFFFFF Const STILL_ACTIVE = &H103& Const glrcErrFileNotFound = 53 Private Declare Function OpenProcess Lib "kernel32" _ (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" _ (ByVal hProcess As Long, lpExitCode As Long) As Long Sub RunApp(strCommand As String, intMode As VbAppWinStyle) ' Run an application, returning immediately to ' the caller. Just presented as a parallel for ' ahtRunAppWait Dim hInstance As Long On Error GoTo ahtRunApp_Err hInstance = Shell(strCommand, intMode) ahtRunApp_Exit: Exit Sub ahtRunApp_Err: Select Case Err.Number Case glrcErrFileNotFound MsgBox "Unable to find '" & strCommand & "'" Case Else MsgBox Err.Description End Select Resume ahtRunApp_Exit End Sub Sub RunAppWait(strCommand As String, intMode As VbAppWinStyle) ' Run an application, waiting for its completion ' before returning to the caller. Dim hInstance As Long Dim hProcess As Long Dim lngRetval As Long Dim lngExitCode As Long On Error GoTo ahtRunAppWait_Err ' Start up the application. hInstance = Shell(strCommand, intMode) hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _ True, hInstance) Do ' Attempt to retrieve the exit code, which will ' not exist until the application has quit. lngRetval = GetExitCodeProcess(hProcess, lngExitCode) DoEvents Loop Until lngExitCode <> STILL_ACTIVE ahtRunAppWait_Exit: Exit Sub ahtRunAppWait_Err: Select Case Err.Number Case glrcErrFileNotFound MsgBox "Unable to find '" & strCommand & "'" Case Else MsgBox Err.Description End Select Resume ahtRunAppWait_Exit End Sub
To initiate it:
RunAppWait "cscript ""D:\DATA\Access\Test Refresh Form in Loop\Test Refresh Form in Loop.vbs""", vbHide
Is there a way to initate the loop with any event on the form start (Open, Load, Resize, Activate, Current)?