Consulting

Results 1 to 14 of 14

Thread: Solved: Option Buttons

  1. #1
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location

    Solved: Option Buttons

    I am succesfully using the following, very basic stuff.

    If OptionBuyJan Then Cells(NextRow, 2) = "January"

    But is it possibly to use a combination of OptionButtons to create data.

    For example

    If OptionBuyDec And OptionBuy2008 Then Cells(NextRow, 3) = "Dec 08"

    I have tried this as is but it didnt return anything.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can't have two option buttons set at the same time.
    ____________________________________________
    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
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    You can't have two option buttons set at the same time.
    Actually you can have multiple option buttons selected at the same time, but all of the different groups of option buttons you want to use have to be encased by their own frames.

    Using the Month and Year example from the first post, you would need to have a frame for Months that has option buttons for every month. Then you could have another frame called Years with option buttons for the different years.

    You cannot select multiple option buttons in the same frame.

    NinjaEdit: I added an example spreadsheet that shows how to use multiple option buttons. When it opens to Sheet1, press Ctrl + Q to launch the UserForm where you can make multiple option button selections and see a result.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by CreganTur
    You cannot select multiple option buttons in the same frame.
    ____________________________________________
    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

  5. #5
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    That's strange... How did you set the value of both option buttons to true? The spreadsheet I uploaded (and other spreadsheets where I use them) won't let me select 2 options buttons in the same frame.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I was messing with you!

    Option buttons have a groupname property that you can set. If they are in different groups, you can set them both, regardless of whether they are in the same frame, different frames, or no frames.
    ____________________________________________
    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

  7. #7
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    I was messing with you!
    Curse you, El Cid!

    Option buttons have a groupname property
    I learn something new every day
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  8. #8
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    XLD so does that invalidate your earlier comment about not being able to set 2 optionbuttons at the same time?? CreganTur, Thanks I see how that works.

  9. #9
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    c

  10. #10
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    CreganTur, What does the 'Me. ' part of this statement signify. Would it work without it?

    If Me.optJan = True Then
    strMonths = "January"

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by maninjapan
    XLD so does that invalidate your earlier comment about not being able to set 2 optionbuttons at the same time?? CreganTur, Thanks I see how that works.
    That comment was made as a response to your question, as I interpreted. If you WANT to set two buttons at a time, you have to program it accordingly.
    ____________________________________________
    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

  12. #12
    VBAX Tutor
    Joined
    Sep 2008
    Posts
    213
    Location
    Ok. and thanks for your help, Ive been able to do what I wanted to do now.

  13. #13
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    CreganTur, What does the 'Me. ' part of this statement signify. Would it work without it?

    If Me.optJan = True Then
    strMonths = "January"
    'Me' is a special keyword that refers to the form that the code is behind. It's a very simple way to refer to objects on the UserForm- it's a lot cleaner and simpler than the longhand method.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  14. #14
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location

    Thumbs up

    Quote Originally Posted by CreganTur
    NinjaEdit: I added an example spreadsheet that shows how to use multiple option buttons. When it opens to Sheet1, press Ctrl + Q to launch the UserForm where you can make multiple option button selections and see a result.
    Randy,

    Your example runs afoul as Excel helps you by interpreting the date and formating it in the cell. I'm attaching a jpeg with the output from executing your code and my added code lines, below. (code is from your UserForm)

    [vba]Private Sub btnExecute_Click()

    Dim strMonths As String
    Dim strYears As String
    Const strDay As String = "01" ' added constant

    If Me.optJan = True Then
    strMonths = "January"
    ElseIf Me.optDec = True Then
    strMonths = "December"
    End If

    If Me.opt07 = True Then
    strYears = "07"
    ElseIf Me.opt08 = True Then
    strYears = "98" ' for A4 entry; was '08' originally
    End If

    Sheet1.Range("A4").Value = strMonths & " " & strYears ' where strYears > 31
    ' Sheet1.Range("A3").Value = strMonths & " " & "20" & strYears
    ' Sheet1.Range("A2").Value = strMonths & " " & strDay & " " & strYears
    ' Sheet1.Range("A1").Value = strMonths & " " & strYears ' XL interprets strYears as being a day date

    End Sub
    [/vba]

    Cheers,
    Ron
    Windermere, FL

Posting Permissions

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