How to call OnDblClick procedure from another Control(s)

WCOK2

New member
Local time
Today, 05:05
Joined
Oct 14, 2006
Messages
6
I have 3 Controls in a form, Control1, Control2, and Control3. Control2, and Control3 both have procedue under event OnDblClick, and I want to wirte code under Control1 OnClick to call OnDblClick of Control2 and then OnDblClick of Control3. Have try several ways but failed. It is another way besides copy whole procedure from OnDblClick into OnClick code?
 
You just have to make the SubRoutine Public instead of Private though it is not necessarily a good coding practice to call another control's event. It makes reading and maintaining code more difficult.
 
First way:

If you set up a demo form with a label called "myLabel" and a button called "myButton" add the code as shown below and it should work.

Code:
Private Sub MyLabel_DblClick(Cancel As Integer)
    MsgBox "Click!"
End Sub

Private Sub MyButton_Click()
    Call MyLabel_DblClick(True)
End Sub

Please note you do not need to use the command "Call", as the code will work without it. However in my opinion it does make your code easier to read.

In this simple test you can use either "true" or "false" here: Call MyLabel_DblClick(True), I haven't studied the significance of this, the usage of this, maybe someone else could advise.
 
Gizmo, that works perfectly for my problem. Thanks a lot.
 

Users who are viewing this thread

Back
Top Bottom