Access VBA Macro Programming

(Joao Candeias) #1

You can view the events by right-clicking the report in Design mode and then clicking
Build Event in the pop-up. Click Code Builder and this will take you into the module for that
report.
In the drop-down at the top-left corner of the module pane (that usually reads
ReportHeader or ReportDetail), select Report. In the drop-down in the right-hand corner of
the module pane, you will be able to access all the events.
The following are the main events you are likely to use:


Activate


The Activate event happens when the user activates the report by putting the focus on it. It is
not the same as the Open or Load event, since the report may already be displayed but does
not have the focus.


Click


The Click event is fired off when the user clicks the mouse somewhere on the report. Do not
forget that controls also have their own on-click events, so you need to guard against where
the user is clicking.


Close


The close event happens when the report is closed, either by the user clicking the Close
button, or through your own code. You may use this event to open another form by using:


Private Sub Report_Close()
DoCmd.OpenReport ("MyReport")
End Sub


Current


The Current event occurs when the user clicks a new row within the report. From its name, it
is easy to confuse it with the Load event because this means that you are selecting a new
record on the form instead of actually loading the form.


Load


The Load event occurs when the report is opened and its data is displayed.


Open


The Open event differs from the Load event in that the Open event does not occur until the
report query has been run. At this point, your report has data on it and your code can interact
with it, whereas when a Load event occurs, the controls have not been populated.


Print


A Print event is fired off when a report is printed out. This can be used to keep a log of who
printed the report out and when.


Chapter 9: Forms and Reports 121

Free download pdf