Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

Up and Down Arrow keys cause different form to load

Dear Experts,

For some reason when a user uses the up or down arrow keys to move between option button selection on a form and the user gets to the last OR first option button and continues to press either the up or down arrow key another form displays. I tried to disable the arrow keys by setting the form's Key Preview event to 'yes' and using the following code in the form's On Key Press event but the other forms still load.

How can I prevent this from happening?

Thanks!

If KeyCode >= 37 And KeyCode <= 40 Then
   KeyCode = 0
End If

Open in new window

0
shogun5
Asked:
shogun5
  • 3
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Did you turn on the Form Key Preview ... set to Yes ?

mx
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Also ... you need to use the Key Down event, which has KeyCode:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
        KeyCode = 0
    End If
End Sub

mx
0
 
shogun5Author Commented:
DatabaseMX,

Yes, I have the Key Preview event set to 'Yes' as I noted. However, I only had code in the "On Key Press" event and not the Key Down event. That worked! Thanks!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Yes ... KeyPress uses KeyAscii and not KeyCode ...

thx.mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now