A.D.TEJPAL
adtp at airtelbroadband.in
Thu Jun 29 00:29:58 CDT 2006
Rusty,
With ShellExecute() API function, it is found that an external file, (e.g. word document) gets printed without any error message, even if the document is already open. Sample code block is given below.
In this context, my sample db named PrintExternalFiles might be of interest to you. It is available at Rogers Access Library (other developers library). Link - http://www.rogersaccesslibrary.com/OtherLibraries.asp#Tejpal,A.D.
Best wishes,
A.D.Tejpal
---------------
=========================================
' Declarations section
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long
------------------------------------------------------------------------------
' Enclose FilePath within double quotes so as to
' take care of embedded spaces if any.
FilePath = Chr(34) & FilePath & Chr(34)
Call ShellExecute(0, "Print", FilePath, "", "", 1)
' Last argument = 1 for Normal Window,
' 6 for Minimized Window, 0 for Hidden
' 3 for Maximized Window
=========================================
----- Original Message -----
From: rusty.hammond at cpiqpc.com
To: accessd at databaseadvisors.com
Sent: Wednesday, June 28, 2006 23:30
Subject: Re: [AccessD] Printing a word document from Access
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