UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Function for KeyDown event    
 
   
StarsFan
post Dec 1 2005, 07:03 PM
Post #1

UtterAccess Guru
Posts: 753
From: Rendon, Texas



Hello UA,

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
Go to the top of the page
 
+
 
Start new topic
Replies (1 - 4)
StarsFan
post Dec 1 2005, 10:21 PM
Post #2

UtterAccess Guru
Posts: 753
From: Rendon, Texas



Been searching but just not coming up with anything on my own. No one want to take a stab at it?
Go to the top of the page
 
+
mhartman
post Dec 1 2005, 11:36 PM
Post #3

UtterAccess Veteran
Posts: 345
From: California



Hello:

Try this:

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight
MsgBox "Right arrow pressed"
forms!YourFormname.SetFocus
Case Else
Your code statements
End Select
End Sub


Regards

Mark
Go to the top of the page
 
+
mhartman
post Dec 1 2005, 11:41 PM
Post #4

UtterAccess Veteran
Posts: 345
From: California



Hello

The above code works if I place a textbox and command button on a form and press the right arrow.

The message box fired back and the focus move to a command button.

I hope this is what your after.

Regards

Mark
Go to the top of the page
 
+
StarsFan
post Dec 1 2005, 11:57 PM
Post #5

UtterAccess Guru
Posts: 753
From: Rendon, Texas



Thanks Mark. That is what I was after.

Shane
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 11:47 AM