msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FindWindow returns incorrect value for OpusApp (I think)

 
Post new topic   Reply to topic    msvisual.com Forum Index -> OLE Automation
Author Message
teddysnips



Joined: 25 Oct 2007
Posts: 1

PostPosted: Thu Oct 25, 2007 7:19 am    Post subject: FindWindow returns incorrect value for OpusApp (I think) Reply with quote

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.

Archived from group: microsoft>public>office>developer>automation
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Thu Oct 25, 2007 1:47 pm    Post subject: Re: FindWindow returns incorrect value for OpusApp (I think) Reply with quote

teddysnips@hotmail.com wrote:
> 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
--
..NET: It's About Trust!
http://vfred.mvps.org
Back to top
View user's profile Send private message
Sinna



Joined: 04 Oct 2007
Posts: 191

PostPosted: Fri Oct 26, 2007 12:44 pm    Post subject: Re: FindWindow returns incorrect value for OpusApp (I think) Reply with quote

Karl E. Peterson wrote:
> teddysnips@hotmail.com wrote:
>> 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.
>


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

Sinna

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
FindWindow returns handle for window that doesen't exist Code Example: Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Sub Const SW_SHOWNORMAL = 1 Dim ret As Long, z As Long ret =

How can I get the value incorrect Hello all£¬ I am writing a program about the database. The part of program as follow For i = 0 To 3 str_detalle = & (i ) Text2(i) = str_detalle Next i In the table ,there are such as

HELP: "The parameter is incorrect" Hi I have created a OCX which initializes correctly when I use the SnapIn Designer to create the nodes and then specify the The problem I have occurrs when I create nodes dynamically and then need specify the resultview using the progid.

Version Incorrect in DXDiag I installed DX 9c on my PC and it looks like it install correctly but when I check the DXDiag It shows I still have DX 8. Anyone know how to fix this or why this would happen?

Incorrect memory information Hello, Does anyone know why the following code yields incorrect memory info? On a 1GB RAM system it reports 1,021MB, seems to be missing 3MB. **** Private Type LARGE_INTEGER LowPart As Long HighPart As Long End Type Private Type dwLength As
Post new topic   Reply to topic    msvisual.com Forum Index -> OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group