FindWindow returns incorrect value for OpusApp (I think)

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.
 
K

Karl E. Peterson

My client's MS Access application, developed in Access2k, has now
stopped working correctly following an update to Access 2007.

Sounds like they gave a new classname to the toplevel Word 2007 window? That's
always a problem when you hardcode assumptions, especially if the assumption is that
Microsoft gives a damn about protecting you and your applications by not arbitrarily
and/or gratuitously changing things that don't need to be changed.
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).

You're trying too hard. Just do something like (aircode alert!)...

On Error Resume Next
Set mobjWordApp = GetObject(, "Word.Application.12")
If Err.Number Then
Set mobjWordApp = CreateObject("Word.Application.12")
End If
On Error GoTo 0

Later... Karl
 
S

Sinna

Karl said:
Sounds like they gave a new classname to the toplevel Word 2007 window? That's
always a problem when you hardcode assumptions, especially if the assumption is that
Microsoft gives a damn about protecting you and your applications by not arbitrarily
and/or gratuitously changing things that don't need to be changed.
<snipped>

That's why I hate using 'constants' that aren't real constants.

Sinna
 
A

atemesov

<snipped>

That's why I hate using 'constants' that aren't real constants.

Sinna

As I have found out in new MS Office 2007 two applications now share
the same object name OpusApp: MS Outlook and MS Word.

If you have any of these applications open your request to:

Set mobjWordApp = GetObject(, "Word.Application.12")

will succeed!!!

Does anyone know how to distinguish between them?

Is there the way to determine if MS Word 2007 is opened?

Thanks in advance.

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top