PDA

View Full Version : Create a new event in VBA



Erdin? E. Ka
09-21-2006, 12:58 PM
Hi everyone! :hi:

I want to create a new event in VBA. For example: "ThreeClick" Event.

It's not a joke, i truly to realize this. Is anybody can give me some model or idea about it?

Many Thanks.

:think:

Jacob Hilderbrand
09-22-2006, 09:04 PM
Can you explain what you want to have the ThreeClick event do?

Erdin? E. Ka
09-22-2006, 10:07 PM
:hi: Hi,

ThreeClick Event just an example.


Private Sub ListBox1_ThreeClick(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox "Thank You Very Much"
End Sub



Actually i want to learn that how to creating "a new event" which is not exist in VBA. I do not need surely ThreeClick, whichever is a new one.

If i can learn that, i will use that in a UserForm for my little accounting program.

Many Thanks. :friends:

stanl
09-23-2006, 03:37 AM
I don't know about creating an event that doesn't exist in VBA already, but you can intercept and modify certain events. For example, suppose you wanted the user to be able to perform a certain action by holding the SHIFT key and right-clicking the mouse. Something like.



Private Sub CommandButton1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button=2 and Shift=1 Then [ call a function of another sub]

End Sub



.02
Stan

Erdin? E. Ka
09-23-2006, 05:38 AM
Hi Stan,:hi:
In fact i could not found my answer but your sample is very interesting for me and i love it. :clap:
And i checked for more samples about your codes, but i could not found the names of other buttons. Shift is ok but what about others?
Can you tell me more about it?
Many thanks... :think:

stanl
09-23-2006, 11:38 AM
your buttons, I believe are

left =1
right =2
center =4

and the keys are enumerated below. The parameters for X and Y are based on position in Twips on a form (I used mainly for grids). Either the MouseDown or MouseUp event can be used to capture any combination of key/mouseclick. Just my opinion, but in any financial workbook etc.. I have ever programmed, I never allowed the user such functionality as it either mentally challenged them or incurred problems... I would always lay out all options as either a menu, dropdown, or button... Stan



Private Sub CommandButton1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

Select Case Shift

Case 0
MsgBox "No key pressed"
Case 1
MsgBox "SHIFT key pressed"
Case 2
MsgBox "CTRL key pressed"
Case 3
MsgBox "CTRL and SHIFT keys pressed"
Case 4
MsgBox "ALT key pressed"
Case 5
MsgBox "ALT and SHIFT keys pressed"
Case 6
MsgBox "CTRL and ALT keys pressed"
Case 7
MsgBox "CTRL, ALT, and SHIFT keys pressed"

End Select

End Sub

Erdin? E. Ka
09-23-2006, 04:15 PM
Hi Stan,

Thank you for all your helps, samples and opinions, those are very special knowledges for me.

Greetings.:friends: