Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2005
    Posts
    144

    Unanswered: Counting Option Buttons

    I have a group of option buttons, 10 to be exact, and a text box on a form. All controls are unbound. I'm trying to determine the number of option buttons NOT checked and display this number in the text box. In other words, out of 10 option buttons, if I check 2, then the text box should read 8. Similarly, if I check no option buttons, the text box should display 10 and if I check all of the buttons, the text box should display 0. Any advice?
    *DaVinci
    "Simplicity is the ultimate sophistication"

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I would declare a public variable to store the number of options checked. Then i would create code to either increment or decrement this value in the onclick event of the option button.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2003
    Posts
    268

    Try This

    Code:
        Dim ctl As Control
        Dim i As Integer
        
        For Each ctl In Controls
            If ctl.ControlType = acOptionButton Then If ctl.Value = True Then i = i + 1
        Next
        
        MsgBox i
    This just looks at each control on a form, if the control is an option button then look to see if it's value is set to true. If so increment the counter.

    after cycling through all of the controls display the number of controls that met the criteria.

  4. #4
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    Quote Originally Posted by DaVinci
    I have a group of option buttons, 10 to be exact, and a text box on a form. All controls are unbound. I'm trying to determine the number of option buttons NOT checked and display this number in the text box. In other words, out of 10 option buttons, if I check 2, then the text box should read 8. Similarly, if I check no option buttons, the text box should display 10 and if I check all of the buttons, the text box should display 0. Any advice?
    Wait a minute! What are you trying to do!? Option groups have sets that are mutually exclusive. Only one Option Button can be selected, not multiples. Also, only the frames have an OnClick event, not the individual Option Buttons. What's your real goal here?

    Sam

  5. #5
    Join Date
    Dec 2003
    Posts
    268

    Depends

    Only if option buttons are implemented within a frame are they mutually exclusive. Implemented in the fashion that he suggests they are simply being used as an alternative to a check box.

    If one wanted to change form option button to checkbox then simply change the enumerated value from acoptionbox to accheckbox.

  6. #6
    Join Date
    Jan 2005
    Posts
    144
    mj is correct. I'm not using the buttons in an Option Group. I'm creating a database for tracking bowling information and the option buttons are representative of the 10 pins in the game. After throwing the first ball, if 2 pins are left standing, I'm tracking which 2 pins they are by clicking the corresponding option buttons. By indicating that 2 pins are left standing, I'm looking to store the true value of the pin count (those pins which were knocked down) in a textbox on the form. The textbox is representative of the frame. This method of tracking standing pins will also allow me to track trends in a bowlers style and advise them on how to improve.
    Attached Thumbnails Attached Thumbnails example.gif  
    *DaVinci
    "Simplicity is the ultimate sophistication"

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Neat! This is one of the more interesting projects I've seen come through here in some time...

    In any event, whether you lean more towards my suggestion or mjweyland's should be based on whether you want your pin count updated in real time or after the user has provided some sort of stimulus.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Jan 2005
    Posts
    144
    The scope of the project is to provide a full-featured personal bowling management solution. The scores (pin counts per frame) will be entered by the bowler and they will have the option of recording the remaining pins for tracking trends. The database will store the bowlers three games in any particular league night, the series (sum) of those games, and will maintain an active record of their average. In addition, I'm planning on incorporating lane conditions and equipment used (ball, shoes, etc) to provide the bowler will trend-related data. This way, if the bowler is playing on especially oily (conditioned) lanes, they can consult the database and determine which equipment to use to maximize their scoring potential.

    I have the entire database layed out on paper, I just have to determine the best approach to some of the more complicated matters like strike scoring. As of right now, the database will be placed on a laptop to be taken with the bowler to the lanes. In the near future, I plan on doing some homework and will begin porting an application of the same nature for palm-like mobile devices. While I understand most of the fundamentals of programming in VBA and utilizing Access' control tools, I may require some assistance with some of the more complicated matters. I'm considering starting a thread here on the board for this project and requesting some assistance in that thread if and when I need it by bumping. I'm really excited about this project. Thanks for the help so far!
    *DaVinci
    "Simplicity is the ultimate sophistication"

  9. #9
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    I'd be inclined to store the actual pins knocked down (or the pins still standing) rather than the pin count. My reasoning is by doing this you have no loss of information and from this you can always re-calculate the scores (I assume!). The benefit is you gain is you can report someones history of pin patterns e.g. how many splits they left, how many times they left pin 1 standing. I don't know enough about the sport so maybe this is irrelevant. I just figure that if you've gone through the pain of designing a pin recording system, it seems pointless to then discard that information (you could have simply entered a number for the number of pins dropped).

    Chris

Posting Permissions

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