Results 1 to 3 of 3
  1. #1

    Counting checked checkboxes on a form

    how does one do it?

    How does one count the number of checked the checkboxes on a form?

    and also hos does one interface the value from radio buttons.

    To put the questions in context, I've got a rate card to computerise.
    The rates are in three categories, in which there are further three
    categories which depend on the number of items booked. for eg. if I
    have Main, appt, tender as the categories and single, triple and many
    as the subcategories in each. How do I check which category and how
    many subcategories have been checked?

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    The Netherlands
    Thanked 0 Times in 0 Posts

    Re: Counting checked checkboxes on a form

    Dim ctl As Control
    Dim nCounter As Integer
    nCounter = 0
    For Each ctl In Forms("YourForm").Controls
    If ctl.ControlType = acCheckBox Then
    If ctl Then nCounter = nCounter + 1
    End If
    Next ctl
    MsgBox nCounter

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Counting checked checkboxes on a form

    It would be a good idea to modify Bart's code slightly. Change this:

    If ctl Then nCounter = nCounter + 1

    To this:

    If (ctl=True) Then nCounter = nCounter + 1

    Since checkboxes can be tri-state, this will avoid errors from the control having a null value. It's always safest to put parens around a control value that you want to evaluate to true or false too because it forces the evaluation.

Posting Permissions

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