Help and Support

HOW TO: Use Automation to Print a Microsoft Word Document using Access 2000

Article ID:210030
Last Review:October 11, 2006
Revision:2.2
This article was previously published under Q210030
On This Page

SUMMARY

This article shows how to use Automation to print a Microsoft Word document that you are working with in a Microsoft Access function or in an Access form's object frame.

The following examples assume you have a Microsoft Word document called C:\Wordtest.doc.

Back to the top

Example - Printing a Microsoft Word Document

This example opens and prints a Microsoft Word document.

1.Start Microsoft Access and open any database.
2.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
					
3.To test this function, type the following line in the Immediate window, and then press ENTER.
? PrintDoc()

Back to the top

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.

1.Start Microsoft Access and open any database.
2.Create a new form not based on any table or query in Design view.
3.Add an unbound object frame control to the form.
4.In the Insert Object dialog box, click Create From File, and then type C:\Wordtest.doc in the File box. Click OK.
5.Set the Name property of the object frame to OLEObj.
6.Add a command button to the form and set the following properties:
Command Button:
-----------------
Name: PrintDoc
Caption: Print Word Doc
OnClick: [Event Procedure]
7.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
					
8.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.
NOTE: In both examples, when the Automation object goes out of scope, the instance of Microsoft Word is unloaded, unless the object was created from a previous instance (already opened).




Back to the top

REFERENCES

For more information about using Automation, click Microsoft Visual Basic Help on the Help menu, type understanding automation in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the Verb property, click Microsoft Visual Basic Help on the Help menu, type verb property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the Action property, click Microsoft Visual Basic Help on the Help menu, type action property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.










Back to the top


APPLIES TO
Microsoft Access 2000 Standard Edition

Back to the top

Keywords: 
kbhowto kbhowtomaster kbinterop KB210030

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.