The following examples assume you have a Microsoft Word document called C:\Wordtest.doc.
Example - Printing a Microsoft Word Document
This example opens and prints a Microsoft Word document.- Start Microsoft Access and open any database.
- Create a module and type the following procedure:
Function PrintDoc() Dim WordObj As Object Set WordObj = CreateObject("Word.Application") WordObj.Documents.Open "C:\Wordtest.doc" WordObj.PrintOut Background:=False WordObj.Quit Set WordObj = Nothing End Function
- To test this function, type the following line in the Immediate window, and then press ENTER.
? PrintDoc()
Example - Printing a Microsoft Word Document in a Form's Object Frame
This example shows how to print an embedded Microsoft Word object on a form.- Start Microsoft Access and open any database.
- Create a new form not based on any table or query in Design view.
- Add an unbound object frame control to the form.
- In the Insert Object dialog box, click Create From File, and then type C:\Wordtest.doc in the File box. Click OK.
- Set the Name property of the object frame to OLEObj.
- Add a command button to the form and set the following properties:
Command Button:
-----------------
Name: PrintDoc
Caption: Print Word Doc
OnClick: [Event Procedure] - Click the Build button next to the command button's OnClick property, and then type the following procedure:
Private Sub PrintDoc_Click() Dim WordObj As Object Me![OLEObj].Verb = -2 'Tells Access to open the application Me![OLEObj].Action = 7 'Activates the application Set WordObj = Me![OLEObj].Object.Application WordObj.PrintOut Background:=False WordObj.Quit Set WordObj = Nothing End Sub
- Open the form in Form view and click the Print Word Doc button.
Note that Microsoft Word starts, prints the document, and then returns to the form.