check if application is running (1 Viewer)

chewy

SuperNintendo Chalmers
Local time
Today, 01:11
Joined
Mar 8, 2002
Messages
581
I am calling the windows calculator from my DB from a button using a shell call. IT works fine however if the user clicks the button again it will start a new instance of calculator. I would like to be able to stop this before they open it if it already running.

How do I check if the windows calculator is running. I saw and example of checking if Word or Excell was running but cannot extend it to any other program

Thanks for any help
 

ghudson

Registered User.
Local time
Yesterday, 20:11
Joined
Jun 8, 2002
Messages
6,194
You need to use the AppActivate statement. This code will test if the calculator
is already open, if true it will set the focus to it, if false then it will open the
calc.exe program.
Code:
Public Function OpenCalculator_Click()
On Error GoTo Err_OpenCalculator_Click
    
    AppActivate "Calculator", False 'Programs Title Bar Name
    
Exit_OpenCalculator_Click:
    Exit Function
    
Err_OpenCalculator_Click:
    If Err.Number = 5 Then 'Invalid procedure call or argument
        Call Shell("C:\Windows\System32\calc.exe", vbNormalFocus)
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_OpenCalculator_Click
    End If
    
End Function
HTH
 

chewy

SuperNintendo Chalmers
Local time
Today, 01:11
Joined
Mar 8, 2002
Messages
581
works great thanks!
 

Users who are viewing this thread

Top Bottom