Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2004, 07:57 AM
Authorized User
 
Join Date: Apr 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to lguzman
Default Printing document from a form & selecting printer

I have created a form that allows you to choose a word document to print. It then shells to word and a Macro prints the document and closes the application.

Is there anyway I can print the document without shelling out to Word.

As well is there a way I can select the printer to print too within that form (Combo box?). At the moment it prints to the default printer and I know that I can change the printer through the Word macro but this would require modifying the macro every time a new printer is added.


Thanks.




[LGuzman]
__________________
[LGuzman]
 
Old June 23rd, 2004, 11:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Quote:
quote:Is there anyway I can print the document without shelling out to Word.
You can use Automation instead. In Access, set a reference to the Microsoft Word x.0 Object Library. Then place the following in your command button's click event:

Private Sub cmdPrintWordDoc_Click()

   ' SET REFERENCE: Microsoft Word x.0 Object Library

   Dim wordApp As Word.Application
   Dim wordDoc As Word.Document

   Set wordApp = CreateObject("Word.Application")
   Set wordDoc = wordApp.Documents.Open("C:\Test.doc")

   wordApp.Visible = False

   wordDoc.PrintOut Background:=False

   ' Quit Word.
   wordApp.Quit

   Set wordApp = Nothing
End Sub

Quote:
quote:is there a way I can select the printer
When the file prints, you can invoke the MSWord Print File Dialog via VBA code in the Word document's code module. Open the Word document in Word and press F11 to open the VBA Editor. Add the following code:

Private Sub Document_Open()
    Dialogs(wdDialogFilePrint).Show
End Sub

The code in the Word VBA module will only execute when the Document object's PrintOut method is called from Access, i.e. the Print File Dialog won't show if you simply open the document in an instance of Word.

HTH,

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting A Printer From Code Rood67 Access 0 August 19th, 2008 02:41 PM
Printing & Setting the margin of document... ravi_bachwala General .NET 1 August 9th, 2007 06:54 PM
Selecting Printer for CRViewer BillsDanny Pro VB 6 3 April 2nd, 2006 08:41 PM
Printing with default printer lletnek Beginning VB 6 1 March 4th, 2004 06:26 PM
Printing directly to a printer Louisa VB.NET 2002/2003 Basics 4 January 16th, 2004 09:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.