T
teddysnips
My client's MS Access application, developed in Access2k, has now
stopped working correctly following an update to Access 2007.
Specifically, attempting to automate Word for a mail merge operation.
In my old code I had a block* where I checked to see if Word was
running: if it was, I'd get an object, otherwise I'd create it. (see
code below). The problem is that the function "modIsRunning" returns
a value of True (the variable lngAppHandle has a value of 66544 after
the call to FindWindow). Therefore the code attempts to call
GetObject, but in fact Word is not running (as I can check via Task
Manager).
How can I adapt my code to determine whether Word is running?
Thanks
Edward
================
' API Declaration
Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal
lpClassName As Any, _
ByVal
lpWindowName As Any) As Long
================
Function modIsRunning(ByVal vstrAppClassName As String) As Boolean
On Error GoTo modIsRunning_Err
' This function returns a flag indicating whether or not an
application is running
' The paramteter vstrAppClassName is the class name (window name)
of the application in question
Dim lngAppHandle As Long
lngAppHandle = FindWindow(vstrAppClassName, 0&)
If (lngAppHandle = 0) Then
modIsRunning = False
Else
modIsRunning = True
End If
modIsRunning_Exit:
Exit Function
modIsRunning_Err:
Call modErrorHandler(Err.Number, Err.Description, "modIsRunning")
Resume modIsRunning_Exit
End Function
================
Public Sub modOpenWordMergeObject(ByVal strMergeFile As String, ByVal
strDataFile As String, ByVal lngLetterCode As Long)
On Error GoTo modOpenWordMergeObject_Err
' Start Word and then configure the mail merge operation
' *Get Word application object
If (modIsRunning("OpusApp")) Then
Set mobjWordApp = GetObject(, "Word.Application.12")
Else
Set mobjWordApp = CreateObject("Word.Application.12")
End If
etc.
stopped working correctly following an update to Access 2007.
Specifically, attempting to automate Word for a mail merge operation.
In my old code I had a block* where I checked to see if Word was
running: if it was, I'd get an object, otherwise I'd create it. (see
code below). The problem is that the function "modIsRunning" returns
a value of True (the variable lngAppHandle has a value of 66544 after
the call to FindWindow). Therefore the code attempts to call
GetObject, but in fact Word is not running (as I can check via Task
Manager).
How can I adapt my code to determine whether Word is running?
Thanks
Edward
================
' API Declaration
Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal
lpClassName As Any, _
ByVal
lpWindowName As Any) As Long
================
Function modIsRunning(ByVal vstrAppClassName As String) As Boolean
On Error GoTo modIsRunning_Err
' This function returns a flag indicating whether or not an
application is running
' The paramteter vstrAppClassName is the class name (window name)
of the application in question
Dim lngAppHandle As Long
lngAppHandle = FindWindow(vstrAppClassName, 0&)
If (lngAppHandle = 0) Then
modIsRunning = False
Else
modIsRunning = True
End If
modIsRunning_Exit:
Exit Function
modIsRunning_Err:
Call modErrorHandler(Err.Number, Err.Description, "modIsRunning")
Resume modIsRunning_Exit
End Function
================
Public Sub modOpenWordMergeObject(ByVal strMergeFile As String, ByVal
strDataFile As String, ByVal lngLetterCode As Long)
On Error GoTo modOpenWordMergeObject_Err
' Start Word and then configure the mail merge operation
' *Get Word application object
If (modIsRunning("OpusApp")) Then
Set mobjWordApp = GetObject(, "Word.Application.12")
Else
Set mobjWordApp = CreateObject("Word.Application.12")
End If
etc.