Consulting

Results 1 to 3 of 3

Thread: Solved: return which Option Button was clicked

  1. #1

    Solved: return which Option Button was clicked

    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
    thank you very much

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Public Function OB_KRvybrany (Byref Btn As MSForms.OptionButton)

    With Btn

    'do your stuff on Btn
    End With
    End Function
    [/vba]

    [vba]
    Private Sub OB_KR5_Click()

    Call OB_KRvybrany(OB_KR5)
    End Sub
    [/vba]
    Last edited by Bob Phillips; 09-13-2010 at 01:27 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Yes, this works exactly what i needed.
    thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •