Summary of Form and Report Events


Access 2007 provides more than 60 different events on forms, form controls, and reports that can trigger macros or Visual Basic procedures. You indicate that you want to respond to an event by providing the name of a macro, a Visual Basic function (preceded by an equal sign), or the special settings [Event Procedure] or [Embedded Macro] as the setting of the event property in the Property Sheet window. When you specify [Event Procedure], Access looks for a Visual Basic procedure in the module stored with the form or report that has the name of the event. When the event property is set to [Embedded Macro], Access executes the related macro embedded in the form or report definition. For details about Visual Basic procedures, see Chapter 19, “Understanding Visual Basic Fundamentals.” For details about creating macros, see Chapter 18, “Automating Your Application with Macros.”

The tables in this section summarize those events and organize them in the following functional categories:

  • Opening and closing forms and reports

  • Changing data

  • Detecting focus changes

  • Detecting filters applied to forms and reports

  • Trapping keyboard and mouse events

  • Detecting changes in PivotTables and PivotCharts

  • Printing

  • Trapping errors

  • Detecting timer expiration

Note 

The event property names listed on the following pages are the names you will see in the property sheet in form or report Design view. To reference an event property from a macro or a Visual Basic procedure, do not include the blanks in the name. For example, the On Load event property in a form property sheet is the OnLoad property of the form. The exceptions to this rule are the 18 events associated with PivotTables and PivotCharts. For those event properties, the name of the event property is the same as the name of the event, which might not match the property name you see in the property sheet.

Table 17–1: Opening and Closing Forms and Reports[1]
Open table as spreadsheet

Event Property (Event Name)

Description

On Close (Close)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user or a close command in your code requests to close the form or the report but before Access clears the screen. Your code that responds to the event cannot cancel the Close event. For forms, the Close event occurs after the Unload event.

On Load (Load)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when Access loads a form or report and then displays the records in the recordset. Your code that responds to the event can set values in controls or set form, report, or control properties. The Load event occurs after the Open event and before the Resize event. Your code cannot cancel a Load event.

On Open (Open)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user or an open command in your code requests to open the form or the report but before Access displays the first record. To gain access to a control on the form or report, your code must specify a GoToControl action or SetFocus method to set the focus on the control. The Open event occurs before Access loads the form or report recordset, so your code that responds to the event can prompt the user for parameters and apply filters. Your code can also change the form or report record source in this event.

On Resize (Resize)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when a form or report changes size. This event also occurs when a form or report opens, after the Load event but before the Activate event. Your code can use this event to force immediate repainting of the resized form or report or to recalculate variables that are dependent on the size of the form. This property has no effect when you are using the single-document interface unless you have also set the Pop Up or Modal property to Yes. When you open a report in Print Preview, this event occurs only when Access opens the report; the event does not occur again if the user resizes the window in Print Preview.

On Unload (Unload)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user or your code requests that the form or report be closed but before Access removes the form or report from the screen. Your code can cancel an Unload event if it determines that a form should not be closed.

[1] These events occur for all views of forms and reports except Design view.

Table 17–2: Changing Data[2]
Open table as spreadsheet

Event Property (Event Name)

Description

After Del Confirm (AfterDelConfirm)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after the user has requested that one or more rows on the form be deleted and after the user has confirmed the deletion. The AfterDelConfirm event also occurs if your code that responds to the BeforeDelConfirm event cancels the deletion. In a Visual Basic procedure, you can test a status parameter to determine whether the deletion was completed, was canceled by your code in the BeforeDelConfirm event, or was canceled by the user. If the deletion was successful, you can use the Requery action within your code that responds to the AfterDelConfirm event to refresh the contents of the form or combo boxes. Your code cannot cancel this event. In an Access project (.adp), this event occurs before the Delete event.

AfterInsert(AfterInsert)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after the user has saved a new record. Your code can use this event to requery a recordset after Access has inserted a new row. Your code cannot cancel this event.

After Update (AfterUpdate)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after the data in the specified form or form control has been updated. See “Understanding Event Sequence and Form Editing” on page 882 for details. Your code that responds to this event cannot cancel it. In the AfterUpdate event of a control, you can, however, use a RunCommand action to choose the Undo command from the Quick Access Toolbar or execute the Undo method of the control. This event applies to all forms and to combo boxes, list boxes, option groups, text boxes, and bound object frames as well as to check boxes, option buttons, and toggle buttons that are not part of an option group.

Before Del Confirm (BeforeDelConfirm)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after Access has deleted one or more rows on the form but before Access displays the standard confirmation dialog box. If your code cancels this event, Access replaces the deleted rows and does not display the confirmation dialog box. In a Visual Basic procedure, you can display a custom confirmation dialog box and then set a return parameter to suppress the standard confirmation dialog box. In an Access project (.adp), this event occurs before the Delete event.

Before Insert (BeforeInsert)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user types the first character in a new record. This event is useful in providing additional information to a user who is about to add records. If your code cancels this event, Access erases any new data on the form. This event occurs prior to the BeforeUpdate event.

Before Update (BeforeUpdate)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure before Access saves changed data in a control to the form’s record buffer or saves the changed record to the database. See “Understanding Event Sequence and Form Editing” on page 882 for details. Your code that responds to this event can examine both the current and previous values of a control. Your code can cancel this event to stop the update and place the focus on the changed control or record. This event is most useful for performing complex validations of data on forms or in controls. This event applies to the same controls as the AfterUpdate event

On Change (Change)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure whenever the user changes any portion of the contents of a combo box control or a text box control. Your code cannot cancel this event. See also the KeyDown and KeyPress keyboard events.

On Delete (Delete)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure just before Access deletes one or more rows. This event occurs once per row being deleted, and your code that responds to the event can examine the data in each row to be deleted. Your code can provide a customized warning message. Your code can also provide automatic deletion of dependent rows in another table (for example, of all the orders for the customer about to be deleted) by executing a delete query. Your code can cancel this event to prevent individual rows from being deleted. (Cancel the BeforeDelConfirm event to cancel deletion of all rows.)

On Dirty (Dirty)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure whenever the user first changes the contents of a bound control on a bound form (a form that has a record source). This event also occurs if your code changes the value of a bound control from a macro (SetValue) or a Visual Basic procedure. Your code that responds to this event can verify that the current record can be updated. Your code can cancel this event to prevent the update. After this event occurs, the Dirty property of the form is True until the record is saved.

On Not In List (NotInList)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user types an entry in a combo box that does not exist in the current recordset defined by the Row Source property for the combo box. Your code cannot cancel this event. Your code can allow the user to create a new entry for the combo box (perhaps by adding a record to the table on which the Row Source property is based). You can also use the List Items Edit Form property to tell Access to open a form to add or edit the records in the recordset of the combo box. In a Visual Basic procedure, you can examine a parameter passed to the event procedure that contains the unmatched text. Your code can also set a return value to cause Access to display the standard error message, display no error message (after your code has issued a custom message), or requery the list after your code has added data to the Row Source property.

On Undo (Undo)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user undoes a change in a form or a text box or combo box control that has been committed to the form’s record buffer. See “Understanding Event Sequence and Form Editing” on page 882 for details. The Undo event does not occur when the user chooses the Undo Typing command. Your code that responds to the event can examine both the current and previous values of the control and cancel the event if the change should not be undone.

On Updated (Updated)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after the data in a form’s object frame control changes. Your code cannot cancel this event. In a Visual Basic procedure, your code can examine a status parameter to determine how the change occurred.

[2] These events occur for forms in Form view or Datasheet view. They do not apply to forms in Design, PivotTable, PivotChart, or Layout view.

Caution 

You can cause an endless loop if your code changes the contents of a control within the event procedure for the control’s Change event.

Table 17–3: Detecting Focus Changes[3]
Open table as spreadsheet

Event Property (Event Name)

Description

On Activate (Activate)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure in a form or a report when the Form or Report window receives the focus and becomes the active window. This event does not occur for pop-up or modal forms. This event also does not occur when a normal Form or Report window regains the focus from a pop-up or modal form unless the focus moves to another form or report. Your code cannot cancel this event.

On Current (Current)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure in a bound form or report when the focus moves from one record to another but before Access displays the new record. Access also triggers the Current event when the focus moves to the first record as a form or report opens. This event is most useful for keeping two open and related forms synchronized. Your code cannot cancel this event. Your code can, however, use GoToRecord or similar action to move to another record if it decides that the form display should not move to the new record. This event does not occur for reports displayed in Print Preview.

On Deactivate (Deactivate)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when a form or a report loses the focus to a window within the Access application that is not a pop-up or modal window. Your code cannot cancel this event.

On Enter (Enter)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the focus moves to a bound object frame, a combo box, a command button, a list box, an option group, or a text box, as well as when the focus moves to a check box, an option button, or a toggle button that is not part of an option group. Your code cannot cancel this event. This event occurs only when the focus moves from another control on the same form or report. If the user changes the focus to another control with the mouse, this event occurs before LostFocus in the current control and before the Enter, GotFocus, MouseDown, MouseUp, and Click events for the new control. If the user changes the focus to a control using the keyboard, this event occurs after the KeyDown, Exit, and LostFocus events in the control that previously had the focus but before the GotFocus, KeyPress, and KeyUp events in the control that is receiving the focus. This event does not occur for reports displayed in Print Preview or forms displayed in PivotTable or PivotChart view.

On Exit (Exit)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the focus moves from a bound object frame, a combo box, a command button, a list box, an option group, or a text box, as well as when the focus moves from a check box, an option button, or a toggle button that is not part of an option group to another control on the same form or report. Your code cannot cancel this event. This event does not occur when the focus moves to another window. If the user leaves a control using the mouse, this event occurs before the Enter, GotFocus, MouseDown, MouseUp, and Click events in the new control. If the user leaves a control using the keyboard, the KeyDown and Exit events in this control occur, and then the Enter, KeyPress, and KeyUp events occur in the new control. This event does not occur for reports displayed in Print Preview or forms displayed in PivotTable or PivotChart view.

On Got Focus (GotFocus)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when an enabled form or report control receives the focus. If a form or report receives the focus but has no enabled controls, the GotFocus event occurs for the form or report. Your code cannot cancel this event. The GotFocus event occurs after the Enter event. Unlike the Enter event, which occurs only when the focus moves from another control on the same form or report, the GotFocus event occurs every time a control receives the focus, including from other windows. This event does not occur for reports displayed in Print Preview or forms displayed in PivotTable or PivotChart view.

On Lost Focus (LostFocus)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when an enabled form or report control loses the focus. The LostFocus event for the form or report occurs whenever a form or report that has no enabled controls loses the focus. Your code cannot cancel this event. This event occurs after the Exit event. Unlike the Exit event, which occurs only when the focus moves to another control on the same form or report, the LostFocus event occurs every time a control loses the focus, including to other windows. This event does not occur for reports displayed in Print Preview or forms displayed in PivotTable or PivotChart view.

[3] These events do not apply to forms or reports in Design view.

Table 17–4: Detecting Filters Applied to Forms and Reports[4]
Open table as spreadsheet

Event Property (Event Name)

Description

On Apply Filter (ApplyFilter)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when a user applies a filter on a form or report from the user interface or via the ApplyFilter command. Setting the form or report’s Filter, OrderBy, ServerFilter, FilterOn, or OrderByOn properties from code does not trigger this event. Your code can examine and modify the form or report’s Filter and Order By properties or cancel the event. Within a Visual Basic procedure, you can examine a parameter that indicates how the filter is being applied.

On Filter (Filter)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user opens the Filter By Form or the Advanced Filter/Sort window. Your code can use this event to clear any previous Filter or Order By setting, set a default Filter or Order By criterion, or cancel the event to prevent the window from opening and provide your own custom filter form. Within a Visual Basic procedure, you can examine a parameter that indicates whether a user has asked to open the Filter By Form or the Advanced Filter/Sort window.

[4] These events apply to forms in Form or Datasheet view and reports in Report view.

Table 17–5: Trapping Keyboard and Mouse Events[5]
Open table as spreadsheet

Event Property (Event Name)

Description

On Click (Click)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user clicks a command button or clicks an enabled form, report, or control. Your code cannot cancel this event. The Click event occurs for a form or report only if no control on the form or report can receive the focus.

On Dbl Click (DblClick)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user double-clicks a bound object frame, a combo box, a command button, a list box, an option group, or a text box, as well as when the user double-clicks a check box, an option button, or a toggle button that is not part of an option group. The Click event always occurs before DblClick. That is, when the user clicks the mouse button twice rapidly, the Click event occurs for the first click followed by DblClick for the second click. Access runs the macro or Visual Basic procedure before showing the user the normal result of the double-click. Your code can cancel the event to prevent the normal response to a double-click of a control, such as activating the application for an ActiveX object in a bound control or highlighting a word in a text box. The DblClick event occurs for a form or report only if no control on that form or report can receive the focus.

On Key Down (KeyDown)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user presses a key or a combination of keys. Your code cannot cancel this event. In a Visual Basic procedure, you can examine parameters to determine the key code (the numeric code that represents the key pressed) and whether the Shift, Ctrl, or Alt key was also pressed. You can also set the key code to 0, in Visual Basic to prevent the control from receiving keystrokes. If the form or report has a command button whose Default property is set to Yes (this indicates that the command button responds to Enter as though the button had been clicked), KeyDown events do not occur when the Enter key is pressed. If the form or report has a command button whose Cancel property is set to Yes (this indicates that the command button responds to the Esc key as though the button had been clicked), KeyDown events do not occur when the Esc key is pressed. See also the Change event. The KeyDown event occurs before KeyPress and KeyUp. If the key the user presses (such as the Tab key) causes the focus to move to another control, the control that has the focus when the user presses the key signals a KeyDown event, but the control that receives the focus signals the KeyPress and KeyUp events. If you set the form’s KeyPreview property to Yes, this event also occurs for the form or report.

On Key Press (KeyPress)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user presses a key or a combination of keys that would result in a character being delivered to the control that has the focus. (For example, KeyPress does not occur for the arrow keys.) Your code cannot cancel this event. In a Visual Basic procedure, you can examine the ANSI key value and set the value to 0, to cancel the keystroke. The KeyPress event occurs after KeyDown and before KeyUp. If the form or report has a command button whose Default property is set to Yes, the KeyPress event occurs for the form or report and the command button when the Enter key is pressed. If the form or report has a command button whose Cancel property is set to Yes, the KeyPress event occurs for the form or report and the command button when the Esc key is pressed. See also the Change event. If you set the form or report’s KeyPreview property to Yes, this event also occurs for the form or report.

On Key Up (KeyUp)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user releases a key or a combination of keys. Your code cannot cancel this event. In a Visual Basic procedure, you can examine parameters to determine the key code and whether the Shift, Ctrl, or Alt key was also pressed. If you set the form or report’s KeyPreview property to Yes, this event also occurs for the form or report. If the form or report has a command button whose Default property is set to Yes, the KeyUp event occurs for the form or report and the command button when the Enter key is released. If the form or report has a command button whose Cancel property is set to Yes, the KeyUp event occurs for the form or report and the command button when the Esc key is released.

On Mouse Down (MouseDown)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user presses any mouse button. Your code cannot cancel this event. In a Visual Basic procedure, you can determine which mouse button was pressed (left, right, or middle); whether the Shift, Ctrl, or Alt key was also pressed; and the X and Y coordinates of the mouse pointer (in twips) when the button was pressed. (Note: There are 1440 twips in an inch.)

On Mouse Move (MouseMove)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user moves the mouse over a form, a report, or a control. Your code cannot cancel this event. In a Visual Basic procedure, you can determine which mouse button was pressed (left, right, or middle) and whether the Shift, Ctrl, or Alt key was also pressed. You can also determine the X and Y coordinates of the mouse pointer (in twips).

On Mouse Up (MouseUp)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user releases any mouse button. Your code cannot cancel this event. In a Visual Basic procedure, you can determine which mouse button was released (left, right, or middle); whether the Shift, Ctrl, or Alt key was also pressed; and the X and Y coordinates of the mouse pointer (in twips) when the button was released.

On Mouse Wheel (MouseWheel)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user rolls the mouse wheel while the focus is on a form or report. In a Visual Basic procedure, you can determine whether rolling the wheel caused the form to display a new page and the count of rows that the view was scrolled. (When the user rolls the mouse wheel, the form scrolls up or down through the records in the form.)

[5] These events apply to forms in Form or Datasheet view and to reports in Report view.

Table 17–6: Detecting Changes in PivotTables and PivotCharts
Open table as spreadsheet

Event Property (Event Name)

Description

After Final Render (AfterFinalRender)

In PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure after all elements in the chart have been rendered (drawn on the screen). Your code cannot cancel this event.

After Layout (AfterLayout)

In PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure after all charts have been laid out but before they have been rendered. In a Visual Basic procedure, you can reposition the title, legend, chart, and axis objects during this event. Your code can also reposition and resize the chart plot area. Your code cannot cancel this event.

After Render (AfterRender)

In PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when a particular chart object has been rendered. In a Visual Basic procedure, you can examine the drawing object and the chart objects and use methods of the drawing object to draw additional objects. Your code cannot cancel this event. This event occurs before the AfterFinalRender event.

Before Query (BeforeQuery)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the PivotTable queries its data source. Your code cannot cancel this event.

Before Render (BeforeRender)

In PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure before an object is rendered. In a Visual Basic procedure, you can determine the type of rendering and the type of object that is about to be rendered. Your code can cancel this event if it determines that the object should not be rendered. This event occurs before the AfterRender and AfterFinalRender events.

Before Screen Tip (BeforeScreenTip)

In PivotTable or PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure before a ScreenTip is displayed. In a Visual Basic procedure, you can examine and change the text of the tip or hide the tip by setting the text to an empty string. Your code cannot cancel this event.

On Cmd Before Execute (CommandBeforeExecute)

In PivotTable or PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure before a command is executed. In a Visual Basic procedure, you can determine the command to be executed and cancel the event if you want to disallow the command. This event occurs before the CommandExecute event.

On Cmd Checked (CommandChecked)

In PivotTable and PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user has selected (checked) a command. In a Visual Basic procedure, you can determine the command selected and disallow the command by setting the value of the Checked parameter to False. Your code cannot cancel this event.

On Cmd Enabled (CommandEnabled)

In PivotTable and PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when a command has been enabled. In a Visual Basic procedure, you can determine the type of command and disable it. Your code cannot cancel this event.

On Cmd Execute (CommandExecute)

In PivotTable and PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure after a command has executed. In a Visual Basic procedure, you can determine the type of command and issue additional commands if desired. Your code cannot cancel this event.

On Data Change (DataChange)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the data fetched or calculated by the PivotTable has changed. In a Visual Basic procedure, you can examine the reason for the change, which could include changing the sort, adding a total, or defining a filter. Your code cannot cancel this event. This event often precedes the DataSetChange event.

On Data Set Change (DataSetChange)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the data source has changed. Your code cannot cancel this event.

On Connect (OnConnect)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the PivotTable connects to its data source. Your code cannot cancel this event.

On Disconnect (OnDisconnect)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the PivotTable disconnects from its data source. Your code cannot cancel this event.

On PivotTable Change (PivotTableChange)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when a field, field set, or total is added or deleted. In a Visual Basic procedure, you can examine the reason for the change. Your code cannot cancel this event.

On Query (Query)

In PivotTable view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the PivotTable must requery its data source. Your code cannot cancel this event.

On Selection Change (SelectionChange)

In PivotTable or PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the user makes a new selection. Your code cannot cancel this event.

On View Change (ViewChange)

In PivotTable or PivotChart view, runs the specified macro, Visual Basic function, or Visual Basic event procedure when the table or chart is redrawn. In a Visual Basic procedure, you can determine the reason for a PivotTable view change. When the form is in PivotChart view, the reason code is always 1. Your code cannot cancel this event.

Table 17–7: Printing
Open table as spreadsheet

Event Property (Event Name)

Description

On Format (Format)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure just before Access formats a report section to print. This event is useful for hiding or displaying controls in the report section based on data values. If Access is formatting a group header, your code has access to the data in the first row of the Detail section. Similarly, if Access is formatting a group footer, your code has access to the data in the last row of the Detail section. Your code can test the value of the Format Count property to determine whether the Format event has occurred more than once for a section (due to page overflow). Your code can cancel this event to keep a section from appearing on the report.

On No Data (NoData)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after Access formats a report that has no data for printing and just before the reports prints. Your code can cancel this event to keep a blank report from printing.

On Page (Page)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure after Access formats a page for printing and just before the page prints. In Visual Basic, you can use this event to draw custom borders around a page or add other graphics to enhance the look of the report.

On Paint (Paint)

Runs the specified macro, Visual Basic function, or Visual basic event procedure just before Access paints a formatted section of a form or report. If you open your report in Layout view or Report view, this event occurs instead of the Format or Print events. If you are using the Format event during printing or displaying your report in Print Preview, you might also need to use the Paint event to see the same result in Layout view or Report view. Your code cannot cancel this event.

On Print (Print)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure just before Access prints a formatted section of a report. If your code cancels this event, Access leaves a blank space on the report where the section would have printed.

On Retreat (Retreat)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when Access has to retreat past already formatted sections when it discovers that it cannot fit a “keep together” section on a page. Your code cannot cancel this event.

Table 17–8: Trapping Errors
Open table as spreadsheet

Event Property (Event Name)

Description

On Error (Error)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure whenever a run-time error occurs while the form or report is active. This event does not trap errors in Visual Basic code; use the On Error statement in the Visual Basic procedure instead. Your code cannot cancel this event. If you use a Visual Basic procedure to trap this event, you can examine the error code to determine an appropriate action.

Table 17–9: Detecting Timer Expiration
Open table as spreadsheet

Event Property (Event Name)

Description

On Timer (Timer)

Runs the specified macro, Visual Basic function, or Visual Basic event procedure when the timer interval defined for the form or report elapses. The Timer Interval property defines how frequently this event occurs in milliseconds. If the Timer Interval property is set to 0, no Timer events occur. Your code cannot cancel this event. However, your code can set the Timer Interval property for the form to 0 to stop further Timer events from occurring.

You should now have a basic understanding of events and how you might use them. In the next section, you’ll see some of these events in action.




Microsoft Office Access 2007 Inside Out
MicrosoftВ® Office Access(TM) 2007 Inside Out (Microsoft Office Access Inside Out)
ISBN: 0735623252
EAN: 2147483647
Year: 2007
Pages: 234

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net