PDA

View Full Version : Solved: return which Option Button was clicked



danovkos
09-13-2010, 12:56 AM
Hi all,
pls. i try to do following.
I have userform with 5 OptionButtons(OB) and other controls.
I want to do, that when is clicked
' one of them, it call universal sub(OB_KR_ALL), but this universal sub will know, which OB was clicked.

I tried to use this code to define public variable for OB.



Public OB_KRvybrany As MSForms.OptionButton


and in my 5 OB (i have OB_KR1, OB_KR2....OB_KR5) subs will this code in this way



Private Sub OB_KR5_Click()
OB_KRvybrany = OB_KR5 ' with this line i want to say, that in variable OB_KRvybrany will be info, which OB was clicked, and then i can use it in this way OB_KRvybrany.BackStyle = fmBackStyleOpaque

Call OB_KR_ALL



but this my example doesnt works :( . It return ERROR "Object variable or with block variable not set"

how to fix it please :dunno
thank you very much

Bob Phillips
09-13-2010, 01:11 AM
Public Function OB_KRvybrany (Byref Btn As MSForms.OptionButton)

With Btn

'do your stuff on Btn
End With
End Function



Private Sub OB_KR5_Click()

Call OB_KRvybrany(OB_KR5)
End Sub

danovkos
09-13-2010, 01:47 AM
Yes, this works exactly what i needed. :)
thank you very much
:clap: :thumb