Link to Word document not working

G

Guest

I have a command button to open and merge data from the current form record
into a Word form. The code below loads Word (showing in Task Manager
Processes tab) but it is not visible.

I'm using Access 2002 and Word 2003

----
Private Sub cmdPrint_Click()

Dim appWord As Word.Application
Dim doc As Word.Document
On Error Resume Next
Err.Clear
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Open("C:\path\filename.doc", , True)
With doc
.FormFields("fld1").Result = Me!Field1
.FormFields("fld2").Result = Me!Field2
.FormFields("fld3").Result = Me!Field3
.Visible = True
.Activate
End With
Set doc = Nothing
Set appWord = Nothing
Exit Sub

errHandler:
MsgBox Err.Number & ": " & Err.Description

End Sub
------
I didn't write this code myself having gleaned it from other sources, as I
don't have the expertise to start from scratch.
To begin with, it wouldn't even open Word in the background until I added
MSWord.olb to the references library.
Any help greatly appreciated.
 
D

Douglas J. Steele

Try setting appWord.Visible = True, rather than simply doc.Visible = True.
 
G

Guest

Update: Partial success. I had to revert to an earlier version of the
database (as I restricted access by removing a toolbar from view - in
preparation for other users) and now Word is opening minimised on the
toolbar, rather than hidden, although Access still has the focus. In
addition, the mailmerged fields work.

Perhaps something can be tweaked so that Word comes to the top and
maximised? Or is the code spot on and there's something amiss with my system.
 

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