+ Reply to Thread
Results 1 to 6 of 6

Optionbutton help

  1. #1
    Craig
    Guest

    Optionbutton help

    HI there,

    I have a Userform with some optionbuttons on it. Named optionbutton1 thru 4.
    Each button is linked to a worksheet cell. I want, that when I click an
    optionbutton it becomes TRUE and the other
    optionbuttons become FALSE.
    I have these buttons grouped.
    What happens is that if optionbutton4 is TRUE and I click optionbutton1...
    optionbutton4 becomes FALSE but optionbutton1 doesn't become TRUE unless I
    click it again.

    How do I make this happen with one click??

    Thanks in Advance...Again!
    Craig



  2. #2
    Patrick Molloy
    Guest

    RE: Optionbutton help

    Make sure that the group is set correctly. What you're asking for is just
    standard behaviour. Whatevert option is clicked gets set to TRUE and the rest
    get set to false. Also make sure that the option buttons are set to the
    correct cells ... they can be pointing at the same cell ... there's no
    warnings ... which might give interesting results


    "Craig" wrote:

    > HI there,
    >
    > I have a Userform with some optionbuttons on it. Named optionbutton1 thru 4.
    > Each button is linked to a worksheet cell. I want, that when I click an
    > optionbutton it becomes TRUE and the other
    > optionbuttons become FALSE.
    > I have these buttons grouped.
    > What happens is that if optionbutton4 is TRUE and I click optionbutton1...
    > optionbutton4 becomes FALSE but optionbutton1 doesn't become TRUE unless I
    > click it again.
    >
    > How do I make this happen with one click??
    >
    > Thanks in Advance...Again!
    > Craig
    >
    >
    >


  3. #3
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Craig,

    Sometimes we overplay our hands in programming. Do you really need "grouping", particularly for a scant number as 4 optionbuttons? If your buttons are left ungrouped, you will achieve (by default) what you want. Namely, by clicking any one button, the others would be automatically set to FASLE.

    Regards
    David.

  4. #4
    Dave Peterson
    Guest

    Re: Optionbutton help

    I think I'd drop the linked cell (ControlSource) and just assign the values with
    code:

    Option Explicit
    Private Sub OptionButton1_Click()
    Call doOpt(1)
    End Sub
    Private Sub OptionButton2_Click()
    Call doOpt(2)
    End Sub
    Private Sub OptionButton3_Click()
    Call doOpt(3)
    End Sub
    Private Sub OptionButton4_Click()
    Call doOpt(4)
    End Sub
    Sub doOpt(which As Long)
    Dim iCtr As Long
    With Worksheets("sheet1")
    For iCtr = 1 To 4
    .Cells(iCtr, "A").Value = CBool(iCtr = which)
    Next iCtr
    End With
    End Sub

    I used Sheet1, A1:A4 (to make my life easier), but you could modify it pretty
    easily.



    Craig wrote:
    >
    > HI there,
    >
    > I have a Userform with some optionbuttons on it. Named optionbutton1 thru 4.
    > Each button is linked to a worksheet cell. I want, that when I click an
    > optionbutton it becomes TRUE and the other
    > optionbuttons become FALSE.
    > I have these buttons grouped.
    > What happens is that if optionbutton4 is TRUE and I click optionbutton1...
    > optionbutton4 becomes FALSE but optionbutton1 doesn't become TRUE unless I
    > click it again.
    >
    > How do I make this happen with one click??
    >
    > Thanks in Advance...Again!
    > Craig


    --

    Dave Peterson

  5. #5
    Craig
    Guest

    Re: Optionbutton help

    Thanks Dave... worked great, my userform has 8 sets of 4 optionbuttons on
    it... so I passed a second value to the doOpt procedure and grouped each set
    of 4.
    I'm really finding that the ControlSource is not very useful... or at least
    has cause me a lot of grief lately! It seems to be the root of my problem
    everytime... I think I'll avoid it in the future.

    Thank for your help again
    Crai

    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    >I think I'd drop the linked cell (ControlSource) and just assign the values
    >with
    > code:
    >
    > Option Explicit
    > Private Sub OptionButton1_Click()
    > Call doOpt(1)
    > End Sub
    > Private Sub OptionButton2_Click()
    > Call doOpt(2)
    > End Sub
    > Private Sub OptionButton3_Click()
    > Call doOpt(3)
    > End Sub
    > Private Sub OptionButton4_Click()
    > Call doOpt(4)
    > End Sub
    > Sub doOpt(which As Long)
    > Dim iCtr As Long
    > With Worksheets("sheet1")
    > For iCtr = 1 To 4
    > .Cells(iCtr, "A").Value = CBool(iCtr = which)
    > Next iCtr
    > End With
    > End Sub
    >
    > I used Sheet1, A1:A4 (to make my life easier), but you could modify it
    > pretty
    > easily.
    >
    >
    >
    > Craig wrote:
    >>
    >> HI there,
    >>
    >> I have a Userform with some optionbuttons on it. Named optionbutton1 thru
    >> 4.
    >> Each button is linked to a worksheet cell. I want, that when I click an
    >> optionbutton it becomes TRUE and the other
    >> optionbuttons become FALSE.
    >> I have these buttons grouped.
    >> What happens is that if optionbutton4 is TRUE and I click
    >> optionbutton1...
    >> optionbutton4 becomes FALSE but optionbutton1 doesn't become TRUE unless
    >> I
    >> click it again.
    >>
    >> How do I make this happen with one click??
    >>
    >> Thanks in Advance...Again!
    >> Craig

    >
    > --
    >
    > Dave Peterson




  6. #6
    Dave Peterson
    Guest

    Re: Optionbutton help

    That seems like a reasonable approach (especially the avoiding portion!).

    Craig wrote:
    >
    > Thanks Dave... worked great, my userform has 8 sets of 4 optionbuttons on
    > it... so I passed a second value to the doOpt procedure and grouped each set
    > of 4.
    > I'm really finding that the ControlSource is not very useful... or at least
    > has cause me a lot of grief lately! It seems to be the root of my problem
    > everytime... I think I'll avoid it in the future.
    >
    > Thank for your help again
    > Crai
    >
    > "Dave Peterson" <[email protected]> wrote in message
    > news:[email protected]...
    > >I think I'd drop the linked cell (ControlSource) and just assign the values
    > >with
    > > code:
    > >
    > > Option Explicit
    > > Private Sub OptionButton1_Click()
    > > Call doOpt(1)
    > > End Sub
    > > Private Sub OptionButton2_Click()
    > > Call doOpt(2)
    > > End Sub
    > > Private Sub OptionButton3_Click()
    > > Call doOpt(3)
    > > End Sub
    > > Private Sub OptionButton4_Click()
    > > Call doOpt(4)
    > > End Sub
    > > Sub doOpt(which As Long)
    > > Dim iCtr As Long
    > > With Worksheets("sheet1")
    > > For iCtr = 1 To 4
    > > .Cells(iCtr, "A").Value = CBool(iCtr = which)
    > > Next iCtr
    > > End With
    > > End Sub
    > >
    > > I used Sheet1, A1:A4 (to make my life easier), but you could modify it
    > > pretty
    > > easily.
    > >
    > >
    > >
    > > Craig wrote:
    > >>
    > >> HI there,
    > >>
    > >> I have a Userform with some optionbuttons on it. Named optionbutton1 thru
    > >> 4.
    > >> Each button is linked to a worksheet cell. I want, that when I click an
    > >> optionbutton it becomes TRUE and the other
    > >> optionbuttons become FALSE.
    > >> I have these buttons grouped.
    > >> What happens is that if optionbutton4 is TRUE and I click
    > >> optionbutton1...
    > >> optionbutton4 becomes FALSE but optionbutton1 doesn't become TRUE unless
    > >> I
    > >> click it again.
    > >>
    > >> How do I make this happen with one click??
    > >>
    > >> Thanks in Advance...Again!
    > >> Craig

    > >
    > > --
    > >
    > > Dave Peterson


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1