Milewskp
asked on
How to pass arguments to functions called by event properties
I would like to set the KeyDown propertyof a combo box to a custom function; eg., = MyFunction(KeyCode).
How can I transfer the value of KeyCode to that function as an argument?
How can I transfer the value of KeyCode to that function as an argument?
Never have seen a way to do that. You need to do code behind control:
Private Sub cboList_KeyDown(KeyCode As Integer, Shift As Integer)
Call MyFunction(KeyCode)
End Sub
mx
Private Sub cboList_KeyDown(KeyCode As Integer, Shift As Integer)
Call MyFunction(KeyCode)
End Sub
mx
I suppose it is possible to extract the latest Keycode via some Windows API(s) calls, but I don't know what those are off hand ... if they exist.
mx
mx
Can you explain why you want to do this? What should happen when the KeyDown event fires?
ASKER
Hi Helen,
I use a subroutine to set certain properties of most combos of my databases. A function I would like to add in this way is that when a combo box has <=3 items in its drop own list, clicking the spacebar while the combo has the focus will cycle through the list.
My subroutine automatically adds functionality to my combo boxes by assigning functions to their event properties. This works great if the function needs no arguments, or if the function can derive the argument after it is called, but in this case I'm stuck.
Something I thought of yesterday is ...maybe the form's keydown event can capture the keycode and save it for later interrogation by the KeyDown event procedure.(?)
I use a subroutine to set certain properties of most combos of my databases. A function I would like to add in this way is that when a combo box has <=3 items in its drop own list, clicking the spacebar while the combo has the focus will cycle through the list.
My subroutine automatically adds functionality to my combo boxes by assigning functions to their event properties. This works great if the function needs no arguments, or if the function can derive the argument after it is called, but in this case I'm stuck.
Something I thought of yesterday is ...maybe the form's keydown event can capture the keycode and save it for later interrogation by the KeyDown event procedure.(?)
>> @ http:#a35771251 ... is that what you meant - note that does not work - just asking if you want to put the function call on the property sheet ?
ASKER
Hi mx,
<is that what you meant >
Yes, normally that's what I do.
<is that what you meant >
Yes, normally that's what I do.
ok ... well, as I do myself. And that certainly works on Events that do not have arguments/parameters ... like say the AfterUpdate event, etc. But in the case of the KeyDown event (et al), assuming you *need* the keycode value (most likely you do) ... then there is no way to grab that value natively in Access.
So, as I noted above ... your only hope would be to find an Windows API call that could retrieve the last keycode value, then use that in your 'common' MyFunction() ... wherein you could place =MyFunction() directly on the event property sheet.
I suspect this API call does exist ...
mx
So, as I noted above ... your only hope would be to find an Windows API call that could retrieve the last keycode value, then use that in your 'common' MyFunction() ... wherein you could place =MyFunction() directly on the event property sheet.
I suspect this API call does exist ...
mx
Has this question been resolved? Can we close the question ?
thx.mx
thx.mx
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
.
The easiest thing to do would be to use a normal event sub for that event, and have that event sub call your UDF or sub, passing the argument values if need be.
Patrick