batwings
Registered User.
- Local time
- Today, 20:05
- Joined
- Nov 4, 2007
- Messages
- 40
Hi there
I have a strange one here,
I am producing TOC's for a number of dossiers using Access as my database and then outputing to a Word doc. the process seems to work fine and all of the documents are produced correctly, I can open one and view it and the book marks are filled with data but when I try to print a document, just as it is sent to the printer all of the bookmarked data dissapears and I am left looking at the document as if it was my original template word doc. I have used this same VBA script before and it all worked well, even when choosing to send straight to the printer rather than saving as individual documents as I am doing now.
Below is my VBA can anyone tell me if the fault is in it? Also I have noticed that even after the last doc has finished Word seems to be sucking up resources and I have to kill its process from the task manager...
I'm using Access 2K3 SP3 and Word 2K3 SP3
it's just doing my head in
Batwings
I have a strange one here,
I am producing TOC's for a number of dossiers using Access as my database and then outputing to a Word doc. the process seems to work fine and all of the documents are produced correctly, I can open one and view it and the book marks are filled with data but when I try to print a document, just as it is sent to the printer all of the bookmarked data dissapears and I am left looking at the document as if it was my original template word doc. I have used this same VBA script before and it all worked well, even when choosing to send straight to the printer rather than saving as individual documents as I am doing now.
Below is my VBA can anyone tell me if the fault is in it? Also I have noticed that even after the last doc has finished Word seems to be sucking up resources and I have to kill its process from the task manager...
I'm using Access 2K3 SP3 and Word 2K3 SP3
Code:
Private Sub Command26_Click()
'Print Dossier TOC
Dim appWord As Word.Application
Dim doc As Word.Document
Dim rst As ADODB.Recordset
'Avoid error 429, when Word isn’t open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set appWord = New Word.Application
End If
'Populate recordset object.
Set rst = New ADODB.Recordset
rst.Open Me.RecordSource, CurrentProject.Connection
'Cycle through records to fill Word form fields.
Do While Not rst.EOF
Set doc = appWord.Documents.Open("F:\Handover_Automation\Dossier\MC.DOC", , True)
With doc
.FormFields("fldSsys").Result = rst!SUBSYSTEM
.FormFields("fldDesc").Result = rst!Description
.FormFields("fldA").Result = rst!AMC
.FormFields("fldE").Result = rst!EMC
.FormFields("fldF").Result = rst!FMC
.FormFields("fldH").Result = rst!HMC
.FormFields("fldI").Result = rst!IMC
.FormFields("fldM").Result = rst!MMC
.FormFields("fldP").Result = rst!PMC
.FormFields("fldS").Result = rst!SMC
.FormFields("fldT").Result = rst!TMC
.Visible = True
.Activate
'The two statements below can be uncommented to save or print the documents when testing of the system is complete
'.PrintOut
'PRINTOUT STATEMENT BELOW PRINTS ONLY THE FIRST PAGE
'.PrintOut True, , wdPrintCurrentPage, , , , , 1
'PRINTOUT STATEMENT BELOW PRINTS ALL PAGES
'.PrintOut True, , wdPrintAllDocument, , , , , 1
'.SaveAs "'" & rst!item & "'"
.SaveAs "F:\Handover_Automation\Dossier\Docs\" & rst!SUBSYSTEM & ""
rst.MoveNext
End With
Loop
Set doc = Nothing
Set appWord = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
End Sub
it's just doing my head in
Batwings