LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 2
Default 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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SetFocus on a different sheet in VBA AaronC Excel Discussion (Misc queries) 1 June 9th 05 11:18 PM
SetFocus using variable name Taras Excel Programming 2 December 4th 03 10:11 PM
SetFocus using variable name Bob Phillips[_6_] Excel Programming 0 December 4th 03 09:47 PM
UserForm1.Textbox1.SetFocus Question Zane Greer Excel Programming 1 September 14th 03 11:59 AM
TextBox.SetFocus steve Excel Programming 4 July 16th 03 07:40 PM


All times are GMT +1. The time now is 07:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"