VBA - disable Up-Arrow key

B

Bob Allen

Excel help for 2007 tells me that I may disable the Up-Arrow key with
Application.OnKey "{UP}","".

I've placed this code in several areas, within several sub-procedures,
including - UserForm_Activate() - and nothing disables the Up_Arrow key.

The application that I am dealing with is in selecting a choice from a
ComboBox. When I use the Slider-bar to position myself halfway through the
choices - I then use the Up-Arrow to make the first choice - and I'm
displaying the choice in a series of CheckBoxX.Caption (where X is an
explicit number from 1 to 13). I set CheckBoxX.Value = True and fill Caption
with text.

When a make a second choice by using the Up-Arrow again, I explicitly set
the Value and the Caption for the next CheckBox - and the system displays
this AND displays a Value = True and the Caption displaying text - on the
screen display of the Form.

HOWEVER - when I explicitly check the third CheckBox Value and Caption, the
Value is False and Caption is Null.

If I then make a third selection with the Up-Arrow key - I then have a
screen display of Checkbox entries that display screen entries for the last 3
selections - but in reverse order. This same reverse order presentation is
present after the second selection.

I'm capturing the number of selections made - 3 - however, the screen
displays 6 displays of CheckBox "data" - although the extraneous displays of
data for Value and Caption are out of sync with the actual contents of Value
and Caption.

I've written a sub-procedure that actually sets Value to False and Caption
to Null prior to the Selections with the Up-Arrow - but this doesn't change
the erroneous screen displays.

Down-Arrow and Mouse-clicks work just fine in the selection process and
screen displays.

I just want to disable the Up-Arrow - but Application.OnKey "{UP}","" fails
to disable the key

WHAT am I doing wrong?

Bob Allen
 
B

Bob Allen

Howdy folk,

After posting this question, I browsed around the Internet a tad and found a
solution. I now have placed that solution in my code. The code is -

Private Sub ComboBox1_KeyDown(ByVal KeyCode As _
MSForms.ReturnInteger, ByVal Shift As Integer)
'Disable Up-arrow key - causing problems in ComboBox selections
If KeyCode = vbKeyUp Then KeyCode = vbNull
End Sub

Now the Up-Arrow key is disabled while the ComboBox has focus.

Thanks for looking at the issue.

Bob Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top