Private Sub object_DblClick(Cancel As Integer)
Object The name of a Form or control.
Cancel The setting determines if the DblClick event occurs. Setting the Cancel argument to True (–1) cancels the DblClick event.
Remarks
On a form, the DblClick event occurs when the user double-clicks a blank area or record selector on the form. For a control, it occurs when the user double-clicks a control or its label in Form view. The DblClick event occurs when the user double-clicks the form or control but before the result of the double-click action occurs (for example, before Microsoft Access selects the word that the insertion point is on in a text box).
- The DblClick event applies only to forms, form sections, and controls on a form, not controls on a report.
- This event doesn't apply to check boxes, option buttons, or toggle buttons in an option group. It applies only to the option group itself.
- This event doesn't apply to a label attached to another control, such as the label for a text box. It applies only to "freestanding" labels. Double-clicking an attached label has the same effect as double-clicking the associated control. The normal events for the control occur, not any events for the attached label.
To run a macro or event procedure when this event occurs, set the OnDblClick property to the name of the macro or to [Event Procedure].
For controls, the result of double-clicking depends on the control. For example, double-clicking a word in a text box selects the entire word. Double-clicking a control containing an OLE object starts the application used to create the object, allowing it to be edited.
If the DblClick event doesn't occur within the double-click time limit of the system, the form, form section, or control recognizes two Click events instead of a single DblClick event. The double-click time limit depends on the setting under Double-Click Speed on the Buttons tab of the Mouse option of Windows Control Panel.
By running a macro or an event procedure when the DblClick event occurs, you can open a window or document when an icon is double-clicked.
Double-clicking a control causes both Click and DblClick events to occur. If the control doesn't already have the focus when you double-click it, the Enter and GotFocus events for the control occur before the Click and DblClick events.
For objects that receive mouse events, the events occur in this order:
MouseDown → MouseUp → Click → DblClick
When you double-click a command button, the following events occur in this order:
MouseDown → MouseUp → Click → DblClick → MouseUp → Click
The second click may have no effect (for example, if the Click macro or event procedure opens a modal dialog box in response to the first Click event). To prevent the second Click macro or event procedure from running, put a CancelEvent action in the DblClick macro or use the Cancel argument in the DblClick event procedure. Note that, generally speaking, double-clicking a command button should be discouraged.
If you double-click any other control besides a command button, the second Click event doesn't occur.
Macro
By running a macro when the DblClick event occurs, you can modify a control's default double-click behavior. For example, you can run a macro before an OLE server is opened in response to double-clicking an embedded object. The macro could display a message asking if the user wants to print or edit the object. You could use a user-defined function to print the object.
You can also use the DblClick event to enable a dialog box to be closed by double-clicking a control instead of clicking the OK button. The DblClick macro would run a Close action for the dialog box. You could also have the macro hide the dialog box by using the SetValue action to set the dialog box's Visible property to No.
You use the CancelEvent action in a DblClick macro to cancel the default double-click behavior of the control. If the user wanted to print the OLE object mentioned earlier in this topic instead of editing it, you would use a user-defined function to print the object, and then use a CancelEvent action to cancel opening of the OLE application.
Example
The following example shows how you can use a DblClick event procedure to open a form that displays records from the table that is the row source of a combo box. When the user double-clicks the Salesperson combo box in an Orders form, the Employees form is displayed, showing the record for the employee selected in the combo box.
To try the example, add the following event procedure to a form named Orders that contains a combo box named EmployeeID. The combo box should have as its row source the same table that is the source for the Employees form (or a query based on that table).
Private Sub EmployeeID_DblClick(Cancel As Integer)
DoCmd.OpenForm "Employees", , , _
"EmployeeID = Forms!Orders!EmployeeID"
End Sub