Results 1 to 6 of 6
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Checking for running Microsoft Programs

    I am trying to have a msgbox state in the title the name of the Microsoft application that is being checked and then in the msgbox state true or false. Currently everything works properly except the title of the msgbox it will not put the application name. Here is the code that i have currently.

    This part is on the form for button click to start the process. it then calls IsAppRunning in the next part of the code. Could someone help me figure this out. Thank you in advance.


    Code:
    Option Compare Database
    Option Explicit
    Dim appString As String
    
    Private Sub btnGetAttach_Click()
    
        MsgBox IsAppRunning(1), , (appString & ".application")
        MsgBox IsAppRunning(6), , (appString & ".application")
        MsgBox IsAppRunning(3), , (appString & ".application")
        MsgBox IsAppRunning(6), , (appString & ".application")
        
    End Sub
    Code:
    Option Compare Database
    
    Public Enum OfficeAppName
     ' enums always start from zero, unless otherwise specified
     ' for demonstration purposes (on the worksheet), start from 1
         OutLook = 1
         PowerPoint = 2
         Excel = 3
         Word = 4
         Publisher = 5
         Access = 6
     End Enum
    
    Function IsAppRunning(appName As OfficeAppName) As Boolean
    'End Function
     ' check if a particular Office app is running
    
    On Error GoTo NotRunning
    
    Dim officeApp As Object
    Dim appString As String
    
     ' assume true
     IsAppRunning = True
    
     ' determine which app is being checked
     Select Case appName
         Case 1 ' Outlook
            appString = "Outlook"
         Case 2 ' PowerPoint
            appString = "PowerPoint"
         Case 3 ' Excel
            appString = "Excel"
         Case 4 ' Word
            appString = "Word"
         Case 5 ' Publisher
            appString = "Publisher"
         Case 6 ' Access
            appString = "Access"
     End Select
    
     ' try to hook into existing object
     Set officeApp = GetObject(, appString & ".Application")
    
    ExitProc:
       Exit Function
    
    NotRunning:
       IsAppRunning = False
       Resume ExitProc
    
     End Function


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If I understand correctly, one of the arguments of MsgBox determines the title, so you just need to populate it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    You have two DIMs for appString. The local DIM in function IsAppRunning overides the DIM in the module. Just remove the DIM in the function.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Sorry for being blind. Note to self, don't post when you're hungry.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You need a global variable. Try this.

    I renamed appString to gAppString

    And I added a couple more lines in Function IsAppRunning()
    Attached Files Attached Files

  6. #6
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I didn't know that one would override the other. thank you very much it works perfectly.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-13-2011, 01:52 PM
  2. Replies: 2
    Last Post: 06-24-2011, 06:38 AM
  3. Running Sum - Microsoft KB290136
    By Kimbertha in forum Queries
    Replies: 8
    Last Post: 10-16-2010, 08:54 PM
  4. Maintenance on programs on open source
    By fsmikwen in forum Access
    Replies: 3
    Last Post: 01-15-2010, 08:43 AM
  5. Tried and true programs no longer run
    By Seckert in forum Access
    Replies: 0
    Last Post: 04-07-2009, 01:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums