DblClick Event - Event Procedures

DblClick Event — Event Procedures

See Also         Example

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