Word Automation printing problem

A

Al

I am printing an MS Word document from MS Access, below is my code.
Development is in Office 2002, my users are using Office 2000. I have set a
reference to the Microsoft Word Object Library 10.0 in my 2002 Access;
however, my Office 2000 users use Microsoft Word Object Library 9.0. To work
around this I have taken the reference out totally and wish to use
late-binding.

The process opens the Word document, populates and updates the fields just
fine. The problem is with the “.ActiveDocumentPrintOut†object (reference **
in the code). I receive Error No: 2465; Description: can’t find the field
‘|’ referrenced in your expression. I believe this is referring to the
output file name. I’m sure this is a syntax problem.

What is the correct syntax for the .ActiveDocument.PrintOut object? This
expression worked fine with the MS Word Object Library 10.0 or 9.0 reference
turned on.

Is there any other efficiencies I should be aware of?

Thanks for your assistance!!

Alan

ACCESS CODE FOLLOWS:

‘DECLARE VARS
Dim appWord As Object
Dim Docs As Object

‘SET MS WORD VARIABLES
strSched = "C:\Templates\Document.dot"
strOutputFileName="C:\Distill\in\" + strFileName + ".ps"

‘OPEN MW WORD AND DOCUMENT
Set appWord = GetObject(, "Word.Application")
Set Docs = appWord.Documents
Docs.Add strSched

‘UPDATE FIELDS IN MS WORD, PRINT DOCUMENT, CLOSE DOCUMENT
With appWord
strActPrinter = .ActivePrinter
.ActivePrinter = "PScript on FILE:"
.ActiveDocument.Fields.Update “PROCESS GETS THIS FAR CORRECTLYâ€

** .ActiveDocument.PrintOut Background:=True,
OutputFileName:=strOutputFileName, Copies:=1, Printtofile:=True, Collate:=True

.ActiveDocument.Close wdSaveChanges = False
.ActivePrinter = strActPrinter
End With

‘QUITE MS WORD AND RESET DIM VARS
appWord.Quit
Set appWord = Nothing
Set Docs = Nothing
 
D

Doug Robbins - Word MVP

It doesn't seem to relate to the error message, but try changing the
Background:=True to Background:=False

With it set to True, your code is probably going on and trying the execute
the next command before the printing has finished and that can cause
problems.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
A

Al

Thanks Doug,

That worked. For production I left background=true so users don't see the
print document box and added a 2 second pause before closing the file. I
also had to change the syntax on the .activedocument.close statement to
.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

to get the document to close.

If you have a better way of doing this please reply otherwise thankyou!!

Thankyou
 

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