Access Word Automation Book marked Text dissapears when printing (1 Viewer)

batwings

Registered User.
Local time
Today, 05:53
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

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
 

boblarson

Smeghead
Local time
Yesterday, 21:53
Joined
Jan 12, 2001
Messages
32,059
Have you tried printing AFTER you have saved the document, instead of printing beforehand?
 

batwings

Registered User.
Local time
Today, 05:53
Joined
Nov 4, 2007
Messages
40
Bob

Yes I have generated 320 documents, they are all saved with seperate filenames to a folder. The problem is when I open one it looks fine all bookmarks are filled as I wanted but, when i hit the print button from Word the document on the screen reverts to empty bookmarks and the printed document is blank...

B:confused:
 

boblarson

Smeghead
Local time
Yesterday, 21:53
Joined
Jan 12, 2001
Messages
32,059
Bob

Yes I have generated 320 documents, they are all saved with seperate filenames to a folder. The problem is when I open one it looks fine all bookmarks are filled as I wanted but, when i hit the print button from Word the document on the screen reverts to empty bookmarks and the printed document is blank...

B:confused:

In the code you have it shows the save as is happening AFTER you print, not before. That's why I asked.
 

batwings

Registered User.
Local time
Today, 05:53
Joined
Nov 4, 2007
Messages
40
Bob

Yes but the PrintOut statements are all commented out so that I can save straight to file.

Code:
'.PrintOut
      'PRINTOUT STATEMENT BELOW PRINTS ONLY THE FIRST PAGE
      '.PrintOut True, , wdPrintCurrentPage, , , , , 1
      'PRINTOUT STATEMENT BELOW PRINTS ALL PAGES
      '.PrintOut True, , wdPrintAllDocument, , , , , 1
 

boblarson

Smeghead
Local time
Yesterday, 21:53
Joined
Jan 12, 2001
Messages
32,059
Could it be this line:
.SaveAs "F:\Handover_Automation\Dossier\Docs\" & rst!SUBSYSTEM & ""

what value does rst!SUBSYSTEM have? Does it include the .doc file extension in the value?
 
M

Mike375

Guest
I have this the end

docName.FilePrint
docName.FileClose (2)

The (2) is to close without saving. Never a printing problem. I don't save because the data inserted into the bookmarks would be saved and thus a foul up on the next run.

As you can see I am using the Word commands

I only scanned this thread so I might be way off the mark.
 

batwings

Registered User.
Local time
Today, 05:53
Joined
Nov 4, 2007
Messages
40
Bob

Sorry about the delay, time difference is to blame i'm GMT +5


Could it be this line:
.SaveAs "F:\Handover_Automation\Dossier\Docs\" & rst!SUBSYSTEM & ""

no it doesn't carry the .doc but all the files are saved as such. With each Subsystem number as the filename and .doc as the extension.

B
 

jubb

Registered User.
Local time
Today, 14:53
Joined
Jul 27, 2005
Messages
50
So from what I can see the docs are generating and saving correctly.

Have you checked the options in Word?, I know there is one (not sure where in 2003) that updates form fields before printing, if this is checked it may cause the problem you are having. I know in 2007 it is under Print | Options, I think there are also options somewhere (once again cannot remember where, in the general options opened from the tools menu) that allow you to stop bookmarks from printing.
 

MrHans

Registered User
Local time
Today, 06:53
Joined
Jul 27, 2015
Messages
147
Not sure if someone still has this issue but it's caused by a setting in Word. I believe you should disable cache while printing or something like that.

When the print job is sent directly to the printer then this shifting of the characters to the left doesn't happen anymore.

Edit: I believe its called Print in the background, just disable that.
 
Last edited:

Users who are viewing this thread

Top Bottom