Solved

Access Event Parameters From A Custom Function

Posted on 2008-10-23
4
293 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now