options buttons are split into 3 pairs of two. at the outset only the
first pair of option buttons is enabled. the following code tests to
see if more than one selection is made in a listbox, and if it is, then
enables a relevant pair of option buttons.
Private Sub Listbox1_change()
'check to see if there is a multiple selection
Dim i As Integer
Dim Acount As Integer
Acount = 0
With Userform1.Listbox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
Acount = Acount + 1
End If
Next i
End With
If Acount > 1 Then
Userform1.OptionButton5.Enabled = True
Userform1.OptionButton6.Enabled = True
End If
End Sub
this code works fine, when i run the code, by stepping through it (using the F8 key). I have tried using Userform1.Repaint, but that doesn't help.
Is there some thing that i am missing that i need to change the appearance of the userform. When i add these same line to my initialize routine, it works. but i don't want to reinitialize, because i fear i will lose the users previous input. sorry just thinking out loud there.
Is there some other trick to getting this change to happen
thanks for your help.

enabling controls at runtime
Kunal105
Does this happen on other people's computers do you want to email me it and I'll see if the problem happens on my machine If you do then send it to dsmyth at mitsuibabcock dot com. I have an idea that it *might* be your hardware acceleration settings for your graphics card but before changing that lets see if it happens all the time or if it's specific to your machine.
Marko Simic
I found the answer. I learned that you are not allowed to reference the name of the userform, within the code on that userform so the code should look like this:
Private Sub Listbox1_change()
'check to see if there is a multiple selection
Dim i As Integer
Dim Acount As Integer
Acount = 0
With Listbox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
Acount = Acount + 1
End If
Next i
End With
If Acount > 1 Then
OptionButton5.Enabled = True
OptionButton6.Enabled = True
End If
End Sub
rather than what is listed above. subtle and tricky. but reaffirms the basic principle that anything extra is probably bad.
Antony Perkov
Hi,
Your code looks fine to me mate. Actually you know what, you don't want to put this code in the ListBox Change event, put it in the ListBox Click event. I believe the ListBox Change event is raised when an item is added or removed from the Listbox, and thats not what your after.
Reza
it's weird, i know the code works. when i step through it, it is fine. but when i run it, that's when there is a problem.
I used the click event rather than a change event, with still no luck.
it doesn't make any sense.
Totally