• Pause to re-sync a VB program (VBA Access2003/WindowsXP)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Pause to re-sync a VB program (VBA Access2003/WindowsXP)

    Author
    Topic
    #422398

    There is a function (or VB statement, or something) in VBVBA that can be called to tell the system to complete any currently running processes before continuing on with the VB code. I’ve used it off and on since Visual Basic 1. But I now can’t remember how to do it.

    Will someone please remind me?

    John Littell

    Viewing 0 reply threads
    Author
    Replies
    • #963260

      I’m not sure – do you mean DoEvents?

      • #963270

        Hans,
        That’s it. Thanks for your help.

        John

        • #963276

          Hans,
          On the use of DoEvents… I need to Shell to another .exe program that will do something irrelevant to this discussion taking perhaps half a second. I need to in effect pause this program until the Shelled program is finished. Does the completion of that Shelled program qualify as an event that DoEvents will wait for? (Grammer!)

          John

          • #963281

            No, DoEvents only gives other processes a chance to do something, it doesn’t wait for them to complete.

            If there is a simple way to determine whether the other app has terminated (a file being created or deleted, for example), use that. Otherwise, you may have to resort to Windows API functions such as CreateProcess and WaitForSingleObject. See the SuperShell example in CreateProcess (warning: annoying but harmless popunder)

            • #963408

              Hans,
              If the VBA Help text had just included your simple sentence of explanation, things would have been a lot clearer. Thanks for pointing me in new directions.

              John

            • #963625

              The preferred way to do this is as follows:

              The Shell statement returns the id of the process created, so use something like the following:

                  ProcessID = Shell("whatever", vbHide)
                  hWndProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, ProcessID)
                  ' Wait for whaever to finish
                  Do
                      If GetExitCodeProcess(hWndProcess, lngProgress) = 0 Then
                          Exit Do
                      Else
                          If lngProgress  STILL_ACTIVE Then
                              Exit Do
                          End If
                      End If
                      DoEvents
                  Loop
              
            • #963652

              Howard, can you post the declarations for the CONSTANT_VALUES in your code snippet? (Or if not constants, structures or whatever…)

            • #963666
            • #963696

              Howard,

              I think Jefferson’s point was that posting code that uses constants without posting the constant declarations doesn’t help those who don’t know where to track them down. The API is rather large and the constants declared for use in the examples are rather numerous, so it would be appropriate to including those declarations when you post bits of code as you did.

    Viewing 0 reply threads
    Reply To: Pause to re-sync a VB program (VBA Access2003/WindowsXP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: