Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

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

    I'm not sure - do you mean DoEvents?

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pause to re-sync a VB program (VBA Access2003/

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

    John

  4. #4
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pause to re-sync a VB program (VBA Access2003/

    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

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pause to re-sync a VB program (VBA Access2003/

    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)

  6. #6
    3 Star Lounger
    Join Date
    May 2002
    Location
    Florence, Oregon, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pause to re-sync a VB program (VBA Access2003/

    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

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pause to re-sync a VB program (VBA Access2003/

    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:

    <pre> 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
    </pre>


  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Pause to re-sync a VB program (VBA Access2003/

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

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Pause to re-sync a VB program (VBA Access2003/

    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.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •