Description
To create an event procedure that runs when the DblClick event occurs, set the OnDblClick property to [Event Procedure], and click the Build button.
Syntax Private Sub Form_DblClick(Cancel As Integer) Private Sub controlname_DblClick(Cancel As Integer) The DblClick event procedure has the following arguments.Argument | Description |
controlname | The name of the control whose DblClick event procedure you want to run. |
Cancel | The setting determines if the DblClick event occurs. Setting the Cancel argument to True (–1) cancels the DblClick event. |
Remarks You can use a DblClick event procedure to modify a control's default double-click behavior. For example, you can have the event procedure run in response to double-clicking an embedded object before an OLE server is opened. The event procedure 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. If the user decides to print the object instead of editing it, you could print the object, and then use the Cancel argument to cancel opening the OLE server.
When you create event procedures for MouseDown, MouseUp, Click, and DblClick events, make sure that their code doesn't conflict. (For example, the Click event procedure shouldn't contain code that cancels actions carried out in the DblClick event procedure.) When you double-click a command button, the following events occur in this order: MouseDown MouseUp Click DblClick MouseUp Click To prevent the second Click event from occurring, you can set the Cancel argument to True (–1) or use the CancelEvent method of the DoCmd object in the DblClick event procedure. If you don't cancel the second Click event, the code in the Click event procedure runs again. The following example cancels the second Click event:Private Sub CmdButton_DblClick(Cancel As Integer)
Cancel = True ' Cancel the second Click event.
End Sub
See Also
DblClick event — macros.
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