Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function for KeyDown

Status
Not open for further replies.

AmigoMobility

Technical User
May 8, 2005
57
US
I've posted this on a couple other forums with no nibbles. Anyone here wanna lend a hand?

I have a number of cmdButtons on a Parent Form that changes the SourceObject
of a subform. I would like to give the user the option of using the Right
Arrow key to SetFocus on the subform. I know I can do this on each cmdButton
using the KeyDown event but what I rather do is create a function to
accomplish this so I don't have to code each and every button. My problem is
I'm new to creating functions, subs and etc. Could I get someone to lend a
hand in accomplishing this, please?

TIA,
Shane
 
Try this as a start
Code:
Option Compare Database

Private Sub Command0_KeyDown(keycode As Integer, Shift As Integer)
Call Keycheck(keycode)
End Sub

Public Sub Keycheck(keycode)
If keycode = 39 Then
  'SET FOCUS WHERE YOU WANT IT
End If
'MsgBox keycode

End Sub
HTH
 
JAdams

Thank you very much. That did get it going.

Just a curious question. If I put =Keycheck() in the On Key Down event is will not work but if I change the On Key Down to an [Event Procedure] and do a "Call" it does work. Why is that?

Thanks again,
Shane
 
The [Event Procedure] causes the code to execute for that event. Although you can type into the events dropdown box(in the controls events tab) I'm not sure there is a use for that. Anyone else know if that has a practical use?
 
The events dropdown is where I'm talking about typing '=Keycheck()'. I am doing this on several other functions that I have going and one advantage that it does do,is it keeps me from having to add code to the form's module. When I say it doesn't work. What it does is fire an error message stating several things but the one I remember is it saying it can't find the macro or function.
 
Replace this:
Public Sub Keycheck(keycode)
By this:
Public Function Keycheck(keycode)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top