Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Counting the number of Checked Checkboxes.


Message #1 by "DON LOWE" <donlowe@s...> on Sat, 19 Jan 2002 18:34:37 +0100
This is a multi-part message in MIME format.



------=_NextPart_000_0006_01C1A117.F32E44A0

Content-Type: text/plain;

	charset="Windows-1252"

Content-Transfer-Encoding: quoted-printable



I have a table with 16 columns each representing a different activity 

that can be carried out in a lesson. If an activity is carried out then 

a checkbox is checked.

I need to be able to count the number of checked checkboxes in each 

column.

Can someone tell me how to do this.

Thanks

Don








Message #2 by Walt Morgan <wmorgan@s...> on Sat, 19 Jan 2002 11:54:58 -0600
Test for .value = ?



True = 1     False = 0









Message #3 by "DON LOWE" <donlowe@s...> on Sat, 19 Jan 2002 22:13:16 +0100
Walt

Thank you for the response, could you give me some sample code to show 

me how to get started.

Much appreciated

Don



Message #4 by "Paul McLaren" <paulmcl@t...> on Sat, 19 Jan 2002 21:12:29 -0000
You can also create a query with the formula,



Value1: Count(iif([ChkBox1] = True,1 ,0))



Replace the Value1 and Chkbox1 as required, repeat for each check box

field.



Depends what your end result is but this is useful for reports amongst

other things.



Regards



Paul









-----Original Message-----

From: Walt Morgan [mailto:wmorgan@s...] 

Sent: 19 January 2002 17:55

To: Access

Subject: [access] Re: Counting the number of Checked Checkboxes.





Test for .value = ?



True = 1     False = 0




















Message #5 by Walt Morgan <wmorgan@s...> on Sat, 19 Jan 2002 15:22:54 -0600
Don,



Assuming you have placed your checkboxes in a control array, you can iterate

through it with something like:



The control array Check1 is an array of your checkboxes. It is 0-based.



Private Sub Command1_Click()

   Dim x as Long

   For x = 0 To Check1.Count - 1

      Debug.Print Check1(x).Value

   Next x

End Sub



Hope this helps.



Walt





Message #6 by "Randy Cornish" <rlcornish@c...> on Sun, 20 Jan 2002 00:27:48
Another way to do this is to create a aggregate (Group By) query.  You 

can place the following in the query (one for each CheckBox field):

     Field:  CountChecks1: Sum(Abs([CheckBox1]))

     Total:  Expression



     Field:  CountChecks2: Sum(Abs([CheckBox2]))

     Total:  Expression



I usually do this sort of thing in code, but this is a quick way to do it.



R



> I have a table with 16 columns each representing a different activity 

> that can be carried out in a lesson. If an activity is carried out then 

> a checkbox is checked.

> I need to be able to count the number of checked checkboxes in each 

> column.

> Can someone tell me how to do this.

> Thanks

Message #7 by "DON LOWE" <donlowe@s...> on Sun, 20 Jan 2002 10:48:21 +0100
Walt, Paul and Randy

Thank you for the help.

Regards

Don



Message #8 by "Gerald, Rand" <RGerald@u...> on Tue, 22 Jan 2002 09:33:44 -0600
Since the values stored in a checkbox (Boolean data type) are 0 = False and

-1 = True, the code below will work.  However, a small change will make it

execute faster.  Instead of Sum(Abs([CheckBox])) use Abs(Sum([CheckBox])).

Abs only needs to be executed once, instead of for each row.



Rand E Gerald

Information Services / Operations



-----Original Message-----

From: Randy Cornish [mailto:rlcornish@c...]

Sent: Saturday, January 19, 2002 6:28 PM

To: Access

Subject: [access] Re: Counting the number of Checked Checkboxes.



Another way to do this is to create a aggregate (Group By) query.  You

can place the following in the query (one for each CheckBox field):

     Field:  CountChecks1: Sum(Abs([CheckBox1]))

     Total:  Expression



     Field:  CountChecks2: Sum(Abs([CheckBox2]))

     Total:  Expression



I usually do this sort of thing in code, but this is a quick way to do it.



R



> I have a table with 16 columns each representing a different activity

> that can be carried out in a lesson. If an activity is carried out then

> a checkbox is checked.

> I need to be able to count the number of checked checkboxes in each

> column.

> Can someone tell me how to do this.

> Thanks






Message #9 by Frazerg@t... on Thu, 24 Jan 2002 04:37:18
Rand 

Fast it may be

But not good if the algorithm is used against different data sources.

If you have an Access table with a true/false fields and a Linked SQL 

Server table with a bit field.

Create a Union Query to return all records in both table

So the Result lokks like this:



Test	    CheckBox

fred      	1

bill      	1

jim       	0

dick      	0

fred      	-1

bill      	-1

jim       	0

dick      	0

Negative values are from Access and Positive values are from SQL



Using Sum(Abs([CheckBox])) would return 4

Using Abs(Sum([CheckBox])) would return 0



So it is better to use Sum(Abs([CheckBox])) so you are asured of the 

accurate result, regardless of how different databases handle logical 

fields



Regards



Greg Frazer



 

> Since the values stored in a checkbox (Boolean data type) are 0 = False 

and

> -1 = True, the code below will work.  However, a small change will make 

it

> execute faster.  Instead of Sum(Abs([CheckBox])) use Abs(Sum

([CheckBox])).

> Abs only needs to be executed once, instead of for each row.

> 

> Rand E Gerald

> Information Services / Operations

> 


  Return to Index