I have an MS Access application and it opens a file from MS Word. Before I close the MS Access form, I need to programmatically determine if the MS Word application is running. I use the following sub and function:
Code:
Private Sub cmdbCloseCC_Click()
On Error GoTo PROC_ERR
Dim wn As String
wn = "Word.Application"
If Me.IsAppRunning(wn) = True Then
wo.Quit
Set wo = Nothing
End If
DoCmd.Close acForm, "frmCC_Status"
Application.Quit
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Sub
___________________________________________
Function IsAppRunning(ByVal appName) As Boolean
Dim oApp As Object
On Error Resume Next
Set oApp = GetObject(, appName) 'Error here - Run-time error '429':
'ActiveX component can't create object
Debug.Print oApp
If Not oApp Is Nothing Then
Set oApp = Nothing
IsAppRunning = True
End If
End Function