ACC2000: Creating an Updatable Unbound Word Object on a Report

ID: Q202056


The information in this article applies to:
  • Microsoft Access 2000


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 this. 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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
The following example enables you to change the header of a report from a form:
  1. Open the sample database, Northwind.mdb.


  2. Click Reports under Objects, and then copy the Sales by Category report.


  3. Name the new report Custom Sales by Category and open it in Design view.


  4. Select and then delete the "Sales By Category" title in the report header.


  5. Select the report header bar.


  6. On the Insert menu, click Object.


  7. 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 blank Word document appears in the report header.


  8. Double-click inside the object to switch to Word.


  9. On the Edit menu, click Select All.


  10. On the Format menu, click Paragraph and change the alignment to Center. Click OK.


  11. Click once anywhere on the report to switch out of Word.


  12. Resize the object as needed and move it to the center of the report header.


  13. Right-click the Word object and click Properties.


  14. On the Other tab, change the Name property of the Word object to, MyTitle. On the Format tab, change the Border property to Transparent.


  15. Set the OnFormat property of the report header to the following event procedure:


  16. 
    Private Sub ReportHeader_Format(Cancel As Integer, _
       FormatCount As Integer)
    
       Me!MyTitle.OleData = Forms!frmRunReport!CustomTitle.OleData
    
    End Sub 
  17. On the File menu of the Visual Basic Editor, click Close and Return to Microsoft Access.


  18. Click the Word document object to select it, and on the Edit menu, click Copy.


  19. Save and close the "Custom Sales By Category" report.


  20. Create a new form and view it in Design view. On the Edit menu, click Paste to insert a copy of the Word document object into the detail section. Finish building the form as follows:


  21. 
    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] 
  22. Set the OnClick property of the RunReport button to the following event procedure:


  23. 
    Private Sub RunReport_Click()
    
       DoCmd.OpenReport "Custom Sales by Category", acViewPreview
    
    End Sub 
  24. On the File menu, click Save.


  25. Switch the frmRunReport form to Form view.


  26. Double-click the Word object and then type My Custom Categories Title.


  27. Change the font size of the title to 14 point and the font style to italic.


  28. Click Run Report.


The Custom 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:

Q226118 OFF2000: Programming Resources for Visual Basic for Applications

Additional query words: heading

Keywords : kbdta AccCon RptEvent KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.