excel - VBA USERFORM: PREVENT COMBOBOX ESCAPE ON KEYDOWN -


community,

there way prevent active combobox losing focus when hitting down arrow (or arrow) when @ end (or start) of list. if there better way (preferably ms standard property) please share.

problem: when @ end of list in combobox, if hit down arrow move whatever control physically below active combobox. vice versa being @ top of combobox , hitting arrow. sloppy , counterproductive. ms excel 2013.

solution: prevent lost focus, in userform's combobox code can enter following:

private sub item1_dropdown_keydown(byval keycode msforms.returninteger, byval shift integer)  select case keycode     case vbkeydown         if item1_dropdown.listindex = item1_dropdown.listcount - 1             item1_dropdown.listindex = item1_dropdown.listindex - 1 'when @ bottom, stay in active combobox         else: item1_dropdown.listindex = item1_dropdown.listindex 'if not @ bottom, keep moving down         end if     case vbkeyup         if item1_dropdown.listindex = 0 'when @ top, stay in active combobox             item1_dropdown.listindex = 1         else:   item1_dropdown.listindex = item1_dropdown.listindex 'if not @ top, keep moving         end if end select       ' "item1_dropdown" name of combobox end sub 

okay, that's how i've been able prevent combobox switching different control when hitting down/up when @ bottom/top of combobox list.

does know of cleaner way this? maybe way without using code?

i don't believe there non-code solution though can shorten code little setting keycode 0 when needed

private sub item1_dropdown_keydown(byval keycode msforms.returninteger, byval shift integer)  select case keycode     case vbkeydown         if item1_dropdown.listindex = item1_dropdown.listcount - 1 keycode = 0     case vbkeyup         if item1_dropdown.listindex = 0 keycode = 0 end select       ' "item1_dropdown" name of combobox end sub 

you use class if need code frequently


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -