Tab out of a UserForm > ListBox ?

CrashDDL

Board Regular
Joined
Oct 17, 2016
Messages
66
Hi,

As the title says. How can I "Tab" out of a ListBox on a UserForm?
I don't understand why, the ".SetFocus" will move cursor to "ListBox2" but focus jumps back after "End Sub".
Anyone has a suggestion for this?

VBA Code:
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

    If KeyCode = 9 Then ListBox2.SetFocus

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Why are you not just setting the tab order for the userform under view menu in VBIDE?
 
Upvote 0
What is VBIDE? Also I have many things on the UserForm but I only allow navigation between 1 x txt, 3 x button and 2 x listboxes. If I can get the Tab out to work from the listboxes...
 
Last edited:
Upvote 0
well the tab is going to move between the controls and you can disable them in tab stops and put them in any order. The VBIDE is the window opens when you click Visual Basic versus just the Macro Window, you can edit/add a macro and it will make a chunk of visual basic code and the editor is the 'Visual Basic Integrated Development Environment' or VBIDE.
 
Upvote 0
Sorry, wasn't aware of the VBIDE name... of course I know what it is now :D
So I did all that. Only the items that I want to be selected have TabStop Enabled.
The problem is that I can't seem to be able to "Tab" out of a "ListBox". Neither of them want to let it happen.
It drags the Focus back for some reason. "Tab" result just won't stick...
 
Upvote 0
Make sure each has a tabstop: true and tabindex: order (tab order can also be set using the ide)
Mine worked fine tab switches between controls just fine with NO additional code attached to the control...
 
Upvote 0
I arrived to the same conclusion. I will have to keep adding the other code bits one by one and check to see which one has this unwanted effect. :)
 
Upvote 0
RARELY do you want keydown to have code...
 
Upvote 0
Any suggestion on what to use instead if I want to trigger a macro when Enter is pressed for example?
 
Upvote 0
Keyup better than Keydown... What are you doing in the macro, or using the macro for?
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top