Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Word Automation printing problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Al - 30 Dec 2004 22:03 GMT
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
Doug Robbins - Word MVP - 30 Dec 2004 22:38 GMT
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.

Signature

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

>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
[quoted text clipped - 56 lines]
>    Set appWord = Nothing
>    Set Docs = Nothing
Al - 31 Dec 2004 04:23 GMT
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

> It doesn't seem to relate to the error message, but try changing the
> Background:=True to Background:=False
[quoted text clipped - 63 lines]
> >    Set appWord = Nothing
> >    Set Docs = Nothing

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.