Solved

Access Event Parameters From A Custom Function

Posted on 2008-10-23
4
295 Views
Last Modified: 2013-11-27
Does anyone know a way to access the parameters exposed by an event in a custom function call?

For example, if you set the OnKeyDown event property for SomeField to [Event Procedure] then access creates the following in the Form's class module:

Private Sub SomeField_KeyDown(KeyCode As Integer, Shift As Integer)

End Sub

I would like to be able to set the OnKeyDown event property for SomeField to =MyKeyDownFunction() and then write a function like:

Public Function MyKeyDownFunction()
    Select Case KeyCode
    Case vbKeyUp
             'Do something
    End Select
End Function

I want to know if there is any way to get to these auto-generated parameters other than setting the event property to "[Event Procedure]".

Thanks.
0
Comment
Question by:mwolfe02
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:fabriciofonseca
fabriciofonseca earned 100 total points
ID: 22787390
Declare a public variable and read its status.

See the attached example.

regards
DoubleClickShift.mdb
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 400 total points
ID: 22787415
I never seen a way to do that.  I've wanted to do that also - especially from the Form Error event.  AFAIK, those are not exposed elsewhere.

mx
0
 
LVL 6

Author Comment

by:mwolfe02
ID: 22788048
fabriciofonseca,

Clever, but you still have to write code in the form's module.  I am trying to avoid [Event Procedure] altogether.


mx,

You were one of the experts I was hoping might have the magic answer.  Form Error is actually the event I had in mind when I asked the question.  I'd love to be able to hide that mysterious 'No current record.' error that rears its ugly head when I start trying to do too much 'magic' on a form.

I'm a big fan of using generic functions in event properties and it irks me when I can't keep a form lightweight just because I need to act on the value of one of these event parameters.

Anyway, yours was the answer I was expecting, but certainly not the one I was hoping for.  I'll leave this question open a few days on the long shot chance that someone out there has figured out how to do this.
0
 
LVL 6

Author Closing Comment

by:mwolfe02
ID: 31509265
I'm giving mx the lion's share of the points because he answered the question most accurately, but I had to throw in something for fabriciofonseca for cleverness and originality.  Thanks to both of you for your help.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question