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:
- Open the sample database, Northwind.mdb.
- Click Reports under Objects, and then copy the Sales by Category report.
- Name the new report Custom Sales by Category and open it in Design view.
- Select and then delete the "Sales By Category" title in the report
header.
- Select the report header bar.
- On the Insert menu, click Object.
- 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.
- Double-click inside the object to switch to Word.
- On the Edit menu, click Select All.
- On the Format menu, click Paragraph and change the alignment to
Center. Click OK.
- Click once anywhere on the report to switch out of
Word.
- Resize the object as needed and move it to the center of the
report header.
- Right-click the Word object and click Properties.
- On the Other tab, change the Name property of the Word
object to, MyTitle. On the Format tab, change the Border property to
Transparent.
- 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
- On the File menu of the Visual Basic Editor, click Close and Return to
Microsoft Access.
- Click the Word document object to select it, and on the
Edit menu, click Copy.
- Save and close the "Custom Sales By Category" report.
- 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:
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]
- Set the OnClick property of the RunReport button to the following
event procedure:
Private Sub RunReport_Click()
DoCmd.OpenReport "Custom Sales by Category", acViewPreview
End Sub
- On the File menu, click Save.
- Switch the frmRunReport form to Form view.
- Double-click the Word object and then type My Custom
Categories Title.
- Change the font size of the title to 14 point and the font style to italic.
- Click Run Report.
The Custom Sales By Category report opens in preview mode with
your custom title.