To create an event procedure that is run when the DblClick event occurs, set the OnDblClick property to [Event Procedure], and click the Build button.
Private Sub Form_DblClick (Cancel As Integer)Private Sub controlname_DblClick (Cancel As Integer)
The DblClick event procedure uses the following arguments.
Argument | Description |
controlname | A string that is the name of the control affected by the DblClick event procedure. |
Cancel | The setting determines if the DblClick event occurs. Setting Cancel to True (-1) cancels the DblClick event. |
You can use a DblClick event procedure to modify a controls default double-click behavior. For example, you can have the event procedure execute in response to double-clicking an embedded object before an OLE application 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 of the OLE application.
This event procedure is also useful for carrying out multiple steps with a single action, such as double-clicking to select an item in a list box or to close a dialog box. To carry out more than one command using a single action, you can use a DblClick event procedure for a list box in tandem with a command button whose Default property is set to True (-1). As part of the DblClick event procedure for the list box, you call the command buttons Click event procedure.
When you create event procedures for MouseDown, MouseUp, Click, and DblClick events, make sure that their code doesnt conflict. (For example, the Click event procedure shouldnt 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:
Click DblClick 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 dont cancel the second Click event, the code in the Click event procedure is run. The following example cancels the second Click event:
Private Sub CmdButton_DblClick (Cancel As Integer) Cancel = True ' Cancel the second Click event.Sub
DblClick Event Macros.
This example shows how you can use a DblClick event procedure to call a Click event procedure for a command button. When the user double-clicks the Products box, the Click event for the Close button is triggered when its Value property is set to True (-1). This causes the Close buttons Click event procedure to run.
To try the following example, add the code to the Declarations section of a form named Main that contains a list box called Products.
Private Sub Products_DblClick (Cancel As Integer) Close_Click ' Trigger Click event.Sub