SetFocus Question
Hi, I am building a very simple Userform with 3 combo boxes and a few
textboxes at the bottom which allows the user to specify the month/day/year.
Month(combo box) contains values 1-12
Day(combo box) contains values 1-31
Year(combo box) contains values 1980-2004
My task is very simple. I want to allow the user to use UP/DOWN arrow key
to traverse thru the values in the combo (for example, 1-12 in the Month
combo box). A weird problem that keeps coming up is that if the value is
already 12 (at the very bottom) in the Month combo box, and I pressed the
DOWN arrow key again, the cursor will jump to another combo or another
textbox. And this problem does not come up in the Day combo box, it stays
at 31 no matter how many times you press the DOWN arrow key.
I tried to use SetFocus function to fix this problem but it doesn't work.
Is there any way to prevent cursors from moving between fields when up/down
arrow keys are pressed? The following is my code. Any suggestion is
greatly appreciated.
Dim Months
Months = Array("01", "02", "03", "04", "05", "06", "07", "08", _
"09", "10", "11", "12")
For i = LBound(Months) To UBound(Months)
cbCalMonth.AddItem Months(i)
Next i
cbCalMonth = Months(8)
Private Sub cbCalMonth_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If (KeyCode = 40) Then
If (cbCalMonth = 12) Then
cbCalMonth.SetFocus (<-- Doesn't work)
End If
End If
End Sub
Also, if I tried to SetFocus to another Combo Box, it works fine. Just that
I can't set focus to the current combo box. Basically, I can't control the
cursor movement when Down arrow key is pressed.
Thanks
|