Solved

Up and Down Arrow keys cause different form to load

Posted on 2011-03-13
4
368 Views
Last Modified: 2012-05-11
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
Comment
Question by:shogun5
  • 3
4 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Did you turn on the Form Key Preview ... set to Yes ?

mx
Capture1.gif
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:shogun5
Comment Utility
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
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Yes ... KeyPress uses KeyAscii and not KeyCode ...

thx.mx
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now