• 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 MVP, Access and Data Platform)Commented:
Did you turn on the Form Key Preview ... set to Yes ?

mx
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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 MVP, Access and Data Platform)Commented:
Yes ... KeyPress uses KeyAscii and not KeyCode ...

thx.mx
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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