How to pass arguments to functions called by event properties

Milewskp
Milewskp used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Commented:
Milewskp,

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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
And I assume you mean you want to do this:

see image ...

mx
Capture1.gif
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
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
Top Expert 2009

Commented:
Can you explain why you want to do this?  What should happen when the KeyDown event fires?

Author

Commented:
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.(?)
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
>>  @ 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 ?

Author

Commented:
Hi mx,
<is that what you meant >
Yes, normally that's what I do.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
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

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Has this question been resolved?  Can we close the question ?

thx.mx
Commented:
In lieu of a better solution, I will use my idea:
<use the form's keydown event can capture the keycode and save it for later interrogation by the KeyDown event procedure>.

Thanks everyone for your input.

Author

Commented:
.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial