Listbox on exit problem

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
In my UserForm in listbox 2 I have listed "Retainer" and "AdHoc"
On exiting Listbox 2, either listbox 3 or Listbox 4 is hidden (Listbox 4 is placed on top of listbox 3) and you then select an item in the visible Listbox.
The problem I am having is that this works fine on leaving Listbox 3 if I press the tab key sas it hides the appropriate listbox and I can just select the correct item. But if I make a mistake and after selecting the item in Listbox 2 I just Click on the next Listbox and it has to be hidden because of my selection in Litbox2, it causes an error
Hope this makes sense. Can I prevent someone from leaving Listbox 2 if they do not press the Tab key or is there another solution.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
My understanding is once you select either Retainer or AdHoc in ListBox2, the ListBox2 become hidden and depending on selection, either ListBox3 or ListBox 4 (since they are on top of each other) will pop up. Therefore, you cannot change to the other selection in ListBox2 due to wrong selection. Is this correct?
 
Upvote 0
My understanding is once you select either Retainer or AdHoc in ListBox2, the ListBox2 become hidden and depending on selection, either ListBox3 or ListBox 4 (since they are on top of each other) will pop up. Therefore, you cannot change to the other selection in ListBox2 due to wrong selection. Is this correct?
Hi Zot
Not quite. I am using code on exit of Listbox2 to hide either listbox3 or Listbox4. If I select Retainer then Listbox3 is hidden when I exit Listbox2 and I select from then from listbox 4. However because my previous selection in listbox2 was Adhoc, Listbox3 is still currently showing and if instead of using Tab to leave Listbox2, I just Click on an item in Listbox3 this creates the error because my selection should hide listbox3 and show listbox4. In your answer above could be the solution that as soon as I select AdHoc or Retainer in Listbox2 it hides one of the listboxes 3 or 4 and it is not an on exit event. is this possible? If so one other question Listbox 3 is Tabindex 3 and listbox 4 is tab index 4. Depending on my selection in Listbox 2 can the tabindex of the hidden Listbox be skipped?
 
Upvote 0
If you do not want to use Tab to select next ListBox or want to skip any ListBox, TextBox or whatever, you can set TabStop in Property to False (True is Default). You don't need to bother about Tab actually.

You can do like this. ListBox value capture selected value

VBA Code:
Private Sub ListBox1_click()

Dim lstAction as String

lstAction = ListBox2.Value

If lstAction = "Retainer" then
' add code to hide or show ListBox here
Else
' add code to hide or show ListBox here
End If

End Sub
 
Upvote 0
Solution
If you do not want to use Tab to select next ListBox or want to skip any ListBox, TextBox or whatever, you can set TabStop in Property to False (True is Default). You don't need to bother about Tab actually.

You can do like this. ListBox value capture selected value

VBA Code:
Private Sub ListBox1_click()

Dim lstAction as String

lstAction = ListBox2.Value

If lstAction = "Retainer" then
' add code to hide or show ListBox here
Else
' add code to hide or show ListBox here
End If

End Sub
Should this be Listbox2_click?
 
Upvote 0
If you do not want to use Tab to select next ListBox or want to skip any ListBox, TextBox or whatever, you can set TabStop in Property to False (True is Default). You don't need to bother about Tab actually.

You can do like this. ListBox value capture selected value

VBA Code:
Private Sub ListBox1_click()

Dim lstAction as String

lstAction = ListBox2.Value

If lstAction = "Retainer" then
' add code to hide or show ListBox here
Else
' add code to hide or show ListBox here
End If

End Sub
Just changed this to Listbox2_Click and it works like a charm. Thanks Zot for your assistance
 
Upvote 0

Forum statistics

Threads
1,214,846
Messages
6,121,905
Members
449,054
Latest member
luca142

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