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