Launch Word 2003 from Access 2003 Under Win7

N

nrms

I'd be grateful if someone could help, if only to direct me elsewhere for a
solution.

I'm using the following code to launch & run a Word 2003 template from a
button on a form in Access 2003. It works well enough, but under Windows 7
RTM the Word Doc opens in a Window **behind** the Access windows with the
focus.

This has never been a problem before, because new opening Windows apps have
always grabbed the screen focus (annoyingly so on occassions). Now for the
first time, it seems, Windows 7 RTM forces the new opening application into
the background. How would I work-round this new behaviour and force the Word
2003 to popup "on top".

Thanks
NigelS

Private Sub Print_Guarantor_Click()
On Error GoTo Print_Guarantor_ClickErr

Dim appWord As Word.Application, docWord As Word.Document

Set appWord = New Word.Application
Set docWord = appWord.Documents.Add("Z:\Templates\Guarantor.dot")
appWord.Visible = True

Print_Guarantor_Click:
Set appWord = Nothing
Exit Sub

Print_Guarantor_ClickErr:
FormattedMsgBox Err.Description
Resume Print_Guarantor_Click

End Sub
 
H

Hans Up

nrms said:
I'm using the following code to launch & run a Word 2003 template from a
button on a form in Access 2003. It works well enough, but under Windows 7
RTM the Word Doc opens in a Window **behind** the Access windows with the
focus.

This has never been a problem before, because new opening Windows apps have
always grabbed the screen focus (annoyingly so on occassions). Now for the
first time, it seems, Windows 7 RTM forces the new opening application into
the background. How would I work-round this new behaviour and force the Word
2003 to popup "on top".

I have 2007 instead of 2003 with Win 7 RTM. But I found the same
behavior you described. On my system, adding appWord.Activate
immediately after "appWord.Visible = True" placed the screen focus on
the Word window.

If that doesn't work for you with Access 2003, you might consider using
Windows API methods to set the focus. I found a discussion of that
technique here:

http://www.xtremevbtalk.com/showthread.php?t=105982
 
N

nrms

Thanks for the useful link to API methods. I had already tried the
Appword.Activate method and this didn't seem to do anything for me in Access
2003.

However the API functions in the link article were useful. In the end my
function became:

Set appWord = New Word.Application
Set docWord = appWord.Documents.Add("Z:\Templates\Guarantor.dot")
appWord.Visible = True
wHwnd = FindWindow(vbNullString, "Document1 - Microsoft Word")
ShowWindow wHwnd, SW_SHOWMINIMIZED
ShowWindow wHwnd, SW_SHOWMAXIMIZED

The only way I could find to get the Window to come to the front was to
minimize it first & then maximize it again - a bit of a kluge but it seems to
work.
 
H

Hans Up

nrms said:
Thanks for the useful link to API methods. I had already tried the
Appword.Activate method and this didn't seem to do anything for me in Access
2003.

However the API functions in the link article were useful. In the end my
function became:

Set appWord = New Word.Application
Set docWord = appWord.Documents.Add("Z:\Templates\Guarantor.dot")
appWord.Visible = True
wHwnd = FindWindow(vbNullString, "Document1 - Microsoft Word")
ShowWindow wHwnd, SW_SHOWMINIMIZED
ShowWindow wHwnd, SW_SHOWMAXIMIZED

The only way I could find to get the Window to come to the front was to
minimize it first & then maximize it again - a bit of a kluge but it seems to
work.

Well done! The API approach doesn't appear near as fiddly as I'd
imagined. I may have to try that myself.
 

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