From: Douglas J. Steele on
Try

onKeyDown= "=myFunction()"


--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"robeito" <robeito(a)discussions.microsoft.com> wrote in message
news:58D1F1AF-1A19-4E65-91CE-36163DCC35C5(a)microsoft.com...
> Hello everybody:
>
> Actual situation of my form:
> onKeyDown= "[Event procedure]"
>
> Desired situation:
> onKeyDown= "myFunction"
>
> I know that myFunction must be in a module, and must be public. But
> I don't know the syntax for doing this !
>
> I want to call myFunction from a lot of forms in my application, so, I
> want
> to write it only once.
> Also, I want to use the parameters KeyCode and Shift that uses the regular
> call of the event.
>
> Thanks in advance
>
>


From: Jon Lewis on
You can normally type "=myFunction()" or if passing parameters
"=myFunction(par1, par2 etc)" (without the quotes) in the Property sheet.
However you want to pass the Key Down event's KeyCode and Shift values and
as far as I know you can only access them from within the Event Procedure so
you're going to have to use the procedure to at least get these values.

So have a public function saved in a Module written something like this:

Public Function myFunction (gKeyCode As Integer, gShift As Integer)
.......do stuff using gKeyCode & gShift
End Function

and then have the following in each form's On KeyDown event procedure:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
myFunction (KeyCode, Shift)
End Sub

On Key Down in the PropertySheet must of course be [Event procedure]

HTH





"robeito" <robeito(a)discussions.microsoft.com> wrote in message
news:58D1F1AF-1A19-4E65-91CE-36163DCC35C5(a)microsoft.com...
> Hello everybody:
>
> Actual situation of my form:
> onKeyDown= "[Event procedure]"
>
> Desired situation:
> onKeyDown= "myFunction"
>
> I know that myFunction must be in a module, and must be public. But
> I don't know the syntax for doing this !
>
> I want to call myFunction from a lot of forms in my application, so, I
> want
> to write it only once.
> Also, I want to use the parameters KeyCode and Shift that uses the regular
> call of the event.
>
> Thanks in advance
>
>


From: Jon Lewis on
Well unless I'm missing something I can't see how a Class will help as the
scope of the KeyCode and Shift is local to each Key Down procedure so,
unless you want to get into creating a keyboard hook which is a completely
different ball game, the values have to be retrieved from within that
procedure. Correct me if I'm wrong though...

Jon

"robeito" <robeito(a)discussions.microsoft.com> wrote in message
news:ECA046AC-4B67-40B3-8592-60408AE6666E(a)microsoft.com...
> Thanks Jon
>
> Your comment is clear to me, but I would like to write no extra code in
> the
> VBA window so maybe I sould try creating a class to handle the form's
> events
>
>