[AccessD] Printing a word document from Access

MartyConnelly martyconnelly at shaw.ca
Wed Jun 28 14:12:28 CDT 2006


If you use

Set appObject = CreateObject("Word.Application")
It will open the last version of word used when you
have multiple versions installed on the machine.

Now you could do this, to call say Word 97 or others

Set appObject = CreateObject("Word.Application.8")

This works if the planets are aligned and OLE
registration hasn't been lost on older versions
of Winword.exe and no changes to ClassID's
when you install multiple versions. There are
known glitches.

You can check what is actually called by 

Debug.Print AppObject.Version

I just realized mine was calling Word 2007 
returned 12.0

So you can upgrade even higher.



rusty.hammond at cpiqpc.com wrote:

>Hey, I didn't get the error with Word 2003!  Another ploy by Microsoft to
>get us to upgrade - let's not fix it until the next version of office ;-)
>
>Oh well, if Gates can get Warren Buffet to hand over $30 billion to his
>foundation, who am I to argue about a few hundred.
>
>Thanks everyone.
>
>
>-----Original Message-----
>From: Heenan, Lambert [mailto:Lambert.Heenan at aig.com]
>Sent: Wednesday, June 28, 2006 10:28 AM
>To: 'Access Developers discussion and problem solving'
>Subject: Re: [AccessD] Printing a word document from Access
>
>
>I just ran this code and it printed out the document without complaint even
>when I had the document open in Word.
>
>Admittedly this is with Access and Word XP (2002).
>
>Sub PrintWordDoc(MyFilePath As String)
>Dim appObject As Word.Application
>
>    Set appObject = CreateObject("Word.Application")
>    appObject.DisplayAlerts = False
>    '**** In the following line, if the file is already open we get an error
>    ' no error for me!
>    appObject.Documents.Open MyFilePath, False, True
>    appObject.Visible = False
>    'lots of options available here
>    appObject.PrintOut _
>    Background:=False, _
>    Append:=False
>    appObject.Documents.Close
>    Set appObject = Nothing
>End Sub
>
>Lambert
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
>rusty.hammond at cpiqpc.com
>Sent: Wednesday, June 28, 2006 10:54 AM
>To: accessd at databaseadvisors.com
>Subject: Re: [AccessD] Printing a word document from Access
>
>
>Thanks Marty but I still get the prompt if the file is already opened
>elsewhere.  Any other ideas?
>
>
>-----Original Message-----
>From: MartyConnelly [mailto:martyconnelly at shaw.ca]
>Sent: Tuesday, June 27, 2006 6:08 PM
>To: Access Developers discussion and problem solving
>Subject: Re: [AccessD] Printing a word document from Access
>
>
>You don't need the newDoc  object try something like
>
> Set AppObject = CreateObject("Word.Application")
>    AppObject.DisplayAlerts = False
>    '**** In the following line, if the file is already open we get an 
>error ****
>    AppObject.Documents.Open MyFilePath, False, True
>   AppObject.Visible = False
>'lots of options available here
>   AppObject.PrintOut _
>        Background:=False, _
>        Append:=False
>
>rusty.hammond at cpiqpc.com wrote:
>
>  
>
>>Using Access 97 and Word 2000, I simply want to open a word or rich 
>>text format (.rtf) file and print it.  If someone already has the file 
>>open,
>>    
>>
>Word
>  
>
>>pops up a dialog saying the file is locked for editing and I have to 
>>choose to open it Read-Only, Notify me when it is closed or Cancel the 
>>request.
>>    
>>
>If
>  
>
>>I click on the Read Only button the file is opened and printed and I'm 
>>on
>>    
>>
>my
>  
>
>>merry way, BUT I need the printing to be automated.  Is there a way to 
>>suppress this prompt?  I'm already telling word to open the document 
>>read only but it doesn't help - any ideas?
>>
>>Sample code follows:
>>
>>Function PrintWordDoc()
>>
>>   Dim AppObject As Object
>>   Dim NewDoc As Object
>>   
>>   Set AppObject = CreateObject("Word.Application")
>>   AppObject.DisplayAlerts = False
>>   '**** In the following line, if the file is already open we get an
>>    
>>
>error
>  
>
>>****
>>   Set NewDoc = AppObject.Documents.Open("c:\logs\rptNewCash.rtf", 
>>False,
>>True)
>>   NewDoc.PrintOut False
>>   NewDoc.Close
>>   AppObject.Quit
>>   Set AppObject = Nothing
>>
>>End Function
>>
>>
>>Rusty Hammond
>>IT Dept. - B-20
>>CPI Qualified Plan Consultants, Inc.
>>(620) 793-8473 ext. 416
>>rusty.hammond at cpiqpc.com
>>
>>
>>**********************************************************************
>>WARNING: All e-mail sent to and from this address will be received, 
>>scanned or otherwise recorded by the CPI Qualified Plan Consultants, 
>>Inc. corporate e-mail system and is subject to archival, monitoring or 
>>review by, and/or disclosure to, someone other than the recipient.
>>**********************************************************************
>> 
>>
>>    
>>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada




More information about the AccessD mailing list