ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SetFocus Question (https://www.excelbanter.com/excel-programming/307538-setfocus-question.html)

Sam

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



Nick

SetFocus Question
 
Hi
The only thing I can think of is for you to check the
Autotab property and the MaxLength property for the
control. If Autotab is true and MaxLength is to 2 then the
focus will jump to the next control when the maximum
length of the field is met.

Not sure this is the solution but you can have a look.

-----Original Message-----
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


.


Sam

SetFocus Question
 
Hi,
I am sure that I set all the AutoTab property to false. What are some other
possibilities that are causing this?
Thanks.


"Nick" wrote in message
...
Hi
The only thing I can think of is for you to check the
Autotab property and the MaxLength property for the
control. If Autotab is true and MaxLength is to 2 then the
focus will jump to the next control when the maximum
length of the field is met.

Not sure this is the solution but you can have a look.

-----Original Message-----
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


.





All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com