Computer Learning Zone CLZ Access Excel Word Windows

Whether or not you can never become great at something, you can always become better at it. Don't ever forget that! And don't say "I'll never be good." You can become better! and one day you'll wake up and you'll find out how good you actually became.

-Neil deGrasse Tyson
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Determine When Process Ends
Wim Bruyn 

3 years ago
Hi Richard,
In the process of finding a solution for my problem described below I found on the internet your videos about Access VBA. I want you to compliment with the quality of the videos and specially about the way you teach a subject. It is always right to the point without unnecessary side paths. I am not one of your students so I hesitated a bit to ask you the question below.
In the past I did wrote several Access VBA applications and I am writing a new one at the moment. For that application I need a functionality to start a web browser from without the VBA application and Suspend (not pause) that VBA code until the web browser is terminated.
As a solution I found a Microsoft article "Determine when a shelled process ends". (https://learn.microsoft.com/en-us/office/vba/access/concepts/windows-api/determine-when-a-shelled-process-ends).
I copied the code into my application and it all works fine for programs like Notepad, Exel, Word etc.
Part of the code:
Private Sub Wait_for_shell_Click()
    ExecCmd "NOTEPAD.EXE": MsgBox "Process 1 Finished"
    ExecCmd "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE": MsgBox "Process 2 Finished"
    ExecCmd "C:\Program Files\Mozilla Firefox\firefox.exe": MsgBox "Process 3 Finished"
    ExecCmd "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe": MsgBox "Process 4 Finished"
End Sub
However, the VBA code is not suspended for both the web browsers Firefox and Edge but suspends for Notepad and Word.
The ExecCmd routine looks as followed:
Public Sub ExecCmd(cmdline As String)
    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    Dim ReturnValue As Integer

' Initialize the STARTUPINFO structure:
    start.cb = Len(start)

' Start the shelled application:
    ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
    Do
        ReturnValue = WaitForSingleObject(proc.hProcess, 0)
        DoEvents
    Loop Until ReturnValue <> 258
    'Loop Until ReturnValue <> 1

    ReturnValue = CloseHandle(proc.hProcess)
End Sub
When debugging the code, I noticed that for Notepad and word the ReturnValue in the Do loop stays on 258 until Notepad or Word terminates.
However, for firefox or Edge the ReturnValue is not 258, so the Do loop terminates immediately.
I have no knowledge c.q. experience about the Windows API so my question is can I use the above method for the functionality I am looking for (I get the feeling not)?
In the meantime, I learned that Firefox is a fundamental other "thing" than Word or Notepad?
Do you have a suggestion for a solution for the above wished functionality?
Regards
Wim Bruyn
Kevin Yip  @Reply  
     
3 years ago
The Devhut website has a procedure that seems to work (I just tried).  It's a relatively short VB sub that uses WMI technique (Windows Management Instrumentation):

https://www.devhut.net/vba-wmi-determine-if-a-process-is-running-or-not/

Just copy the code to a standard module in Access.  I ran the following test and it worked -- the code correctly waited for Firefox to exit:

Sub WMITest()
    Shell "C:\Program Files\Mozilla Firefox\firefox.exe"
    Do Until Not WMI_IsProcessRunning("firefox.exe")
    Loop
    MsgBox "Process ended."
End Sub

In Devhut's code, notice that it actually runs a query that checks if a process is running or not:

     "SELECT * FROM Win32_Process WHERE Name = '" & sProcessName & "'"

Regarding the original code you used, I've used it for years -- since the 1990s, so it goes way back.  It works with lots of programs, like VLC, Adobe Reader, etc., but it also doesn't work with many, like Firefox, Thunderbird, etc.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/8/2026 9:28:46 PM. PLT: 1s