ACC: How to Create an Updatable Unbound Word Object on a Report (190137)



The information in this article applies to:

  • Microsoft Access for Windows 95 7.0
  • Microsoft Access 97

This article was previously published under Q190137

SUMMARY

For special formatting considerations, you may want to include a Microsoft Word object on a Microsoft Access report. For example, you may want to give a user the ability to change the font size of a title without having to switch the report to design mode. This article shows you how to do so. The technique described is especially useful in a Microsoft Access run-time application.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following example enables you to change the header of a report from a form:
  1. Open the sample database Northwind.mdb, and then open the Sales By Category report in Design view.
  2. Select and then delete the Sales By Category title in the report header.
  3. Select the report header bar.
  4. On the Insert menu, click Object.
  5. In the Insert Object dialog box, click Create New, and then in the Object Type list, click Microsoft Word Document. Click OK.

    Note that a Microsoft Word document opens. Do not type anything in the document.
  6. On the File menu, click "Close & Return to Sales by Category: Report."

    Note that a blank Microsoft Word Document appears in the report header.
  7. Resize the object as needed and move it to the center of the header.
  8. Change the Name property of the Microsoft Word object to MyTitle.
  9. Set the OnFormat property of the report header to the following event procedure:
           Private Sub ReportHeader_Format(Cancel As Integer, _
             FormatCount As Integer)
    
              Me!MyTitle.OleData = Forms!frmRunReport!CustomTitle.OleData
    
           End Sub
    					
  10. Select the Microsoft Word document object. On the Edit menu, click Copy.
  11. Save and close the Sales By Category report.
  12. Create a new form. On the Edit menu, click Paste to insert a copy of the Microsoft Word Document object, and then finish building the form as follows:
           Form: frmRunReport
           ------------------------------------------------------
           Caption: Run Report
    
           Unbound Object frame (Microsoft Word Document object):
              Name: CustomTitle
              Locked: No
              Enabled: Yes
           Command button:
              Name: RunReport
              Caption: Run Report
              OnClick: [Event Procedure]
    					
  13. Set the OnClick property of the RunReport button to the following event procedure:
           Private Sub RunReport_Click()
    
              DoCmd.OpenReport "Sales by Category", acViewPreview
    
           End Sub
    					
  14. On the File menu, click Save.
  15. Switch the frmRunReport form to Form view.
  16. Double-click the Microsoft Word object, and then type "My Custom Categories Title" (without the quotation marks).
  17. Change the font size of the title to 14 and the font style to italic.
  18. Click Run Report.
Note that the Sales By Category Report opens in preview mode with your custom title.

REFERENCES

For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

163435 VBA: Programming Resources for Visual Basic for Applications


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbProgramming KB190137