Listbox.RowSource problem

  • Thread starter Thread starter Tim Coddington
  • Start date Start date
T

Tim Coddington

Given a simple form with one listbox, I have loaded the code as follows:

Private Sub UserForm_Initialize()
ListBox1.RowSource = "A1:A26"
End Sub
Private Sub ListBox1_Click()
ListBox1.RowSource = ""
ListBox1.RowSource = "A9:A14"
End Sub

where A1 .. A26 are the letters of the alphabet.
Question 1:
Putting a break in Listbox1_Click() shows that when I click on the listbox,
ListBox1_Click() fires two times. Why is that so?
Question 2:
When I click on the listbox, why aren't the contents of the listbox changed
to reflect the new rowsource?

Thanks for any help!
-Tim
 
Tim,

If you put this code in a module

Private Sub UserForm_Initialize()
Userform1.ListBox1.RowSource = "A1:A26"
End Sub
and this in your code for userform
Private Sub ListBox1_Click()
Unload userform1
With Userform1
.ListBox1.RowSource = ""
.ListBox1.RowSource = "A9:A14"
..show
End With
End Sub
I beleive it should do what you want.

Charles
 
Are you saying that every time I need to reset .RowSource I need to save all
my other fields on that form, unload the form, adjust .RowSource, and then
reload all my other fields????
 
Tim,
I think when you Initialize the userform it retains the current information.
Then when you select an item in the listbox (even though you say to clear
the listbox) it still holds the image from the Initialization. By dismissing
the form then recall it now takes on the new properties. Maybe someone else
can explain it better than me.

Charles
 
Tim,
It was suggested that you use Dbl_Click by mangesh_yadav on the Forum. That
should solve your problem.
 
I'm sorry, Mr Harmon, but I do not know about any forum. How do I get there
to read up on this artical by mangesh_yadav?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top