Count number of Yes's

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

I have 18 combo boxes that contain the choice of Yes, No, Partial, N/A.
I have a text box called "YesCount", "NoCount", "PartialCount", "NACount".
I want each of those boxes to count the number of Yes, No, Partial, N/A
selected on the form. How can this be done?
 
I have 18 combo boxes that contain the choice of Yes, No, Partial, N/A.
I have a text box called "YesCount", "NoCount", "PartialCount", "NACount".
I want each of those boxes to count the number of Yes, No, Partial, N/A
selected on the form. How can this be done?

Add a command button to the form.
Code it's click event:

Me.YesCount = 0
Me.NoCount = 0
Me.PartialCount = 0
Me.NACount = 0
Dim c As Control
For Each c In Me.Section(0).Controls
If TypeOf c Is ComboBox Then
If c.Value = "Yes" Then
Me.YesCount = Nz(Me.YesCount, 0) + 1
ElseIf c.Value = "No" Then
Me.NoCount = Nz(Me.NoCount, 0) + 1
ElseIf c.Value = "Partial Count" Then
Me.PartialCount = Nz(Me.PartialCount, 0) + 1
ElseIf c.Value = "N/A" Then
Me.NoCount = Nz(Me.NACount, 0) + 1
End If
End If
Next c

Each time you click the button, the totals will display.
 
Nice code Fred,it made me think. but I did see one error.

This line

ElseIf c.Value = "Partial Count" Then

should be

ElseIf c.Value = "Partial" Then (without the 'Count' )



I had to look up the Section Property info. This is what I found:

The Section property corresponds to a particular section. You can use the
following constants listed below. It is recommended that you use the
constants to make your code easier to read.

Setting Constant Description

0 - acDetail - Form detail section or report detail section
1 - acHeader - Form or report header section
2 - acFooter - Form or report footer section
3 - acPageHeader - Form or report page header section
4 - acPageFooter - Form or report page footer section
 
Back
Top