Start/End events

Start/end events occur when the report starts and the report ends. The only report data you have access to from start/end events are report legends, which you can set or return in the Start event. To access report fields, you must use band events.

Start event

The Start event occurs just before the report starts to print, before any data actually prints. The primary use of the Start event is to set report legends using the Legend property. Legends are fields whose data is persistent throughout the report, and which must be passed to the report as it starts. The following example sets the value of a legend field from the Start event:

Private Sub Report_Start()
	RMCustomerReport.Legend(2) = "Aging Period Amount"
End Sub

You can also use the report’s Start event to initialize any module-level variables you’ll use for the report. The following examples use a module-level variable named Count to restrict a report to 10 customer records. The Start event sets the counter to 0, then the BeforeAH event increments the counter. After 10 records print, the BeforeAH event cancels the report using the Cancel method.

'Declare a module-level variable
Private Count As Integer
---------------------------------------------------------------
Private Sub Report_Start()
	'Initialize the count
	Count = 0
End Sub
---------------------------------------------------------------
Private Sub Report_BeforeAH(ByVal Level As Integer, _
SuppressBand As Boolean)
	'Increment the count
	Count = Count + 1
	If Count = 11 Then
		RMCustomerReport.Cancel
	End If
End Sub

End event

The End event occurs after a report prints. Use this event to perform any clean-up activities for the report, launch other applications, or open and close other windows. For example, the following End event procedure launches Microsoft Outlook® after the RM Customer Report prints:

Private Sub Report_End()
	Dim Response As Integer
	Dim RetVal As Variant
	Response = MsgBox("Do you want to launch MS Outlook?", vbYesNo)
	If Response = vbYes Then
		RetVal = Shell("C:\Program Files\Microsoft Office\ + _
		"Office\Outlook.exe", vbNormalFocus)
	End If
End Sub


Documentation Feedback