Count ticked in check box and displaying in a text box?

adanoob

Registered User.
Local time
Tomorrow, 03:59
Joined
Oct 9, 2009
Messages
20
hi, anyone knows how to count the numbers of tick i've clicked on a check box and display it on a text box? when i clicked on the check box my text box appears -1. do i need to create a query? pls help me on this
 
What are you actually trying to count? The number of times a user has clicked on a checkbox? The number of checkboxes that are True/False? More help please

David
 
Try using;
Code:
ABS(CehckName)
as the source for your text box.

Text boxes return -1 for checked or true and 0 for uncheck or False.

the ABS() function simply returns a negative number as a positive or absolute result.
 
hi DCrake, i wanna count the no of times when user click on checkbox...
 
hi John Big Booty, where do i put the code? open the code builder property?
 
If you are simply trying to count the times a single check box is clicked you will need add some additional code to the OnClick event of the check box;

Code:
Me.TextBoxName = Me.TextBoxName + 1

If you want to see if a check box has been checked or not you can use the code I gave previously as the ControlSource for your text box, then if the check box is check the text box will have a value of one, or zero if it is unchecked.
 
Why would you want to count the number of times a checkbox has been ticked? Do you want to carry this figure over each time the record is edited?

David
 
i wanna know the total of number of ticks on the checkbox so i can sum it up and display the number of ticks.
 
Again, if I have a control on a form that is a tick box every time I click it it changes from True to False, back to True, etc. What is prompting the user to tick the box? and what is the purpose? a copy of the form might clear things up.

David
 
Can I hazard a guess here - adanoob is this a continuous form with check boxes on and you want a count of how many are checked?
 
ok i'll give an eg here... the check box i use to count how many game console has sold with controller? or without controller, for that 1st person. so in the form i'll have a text box like this "total number sold with cotroller" and "total number sold without controller" so my puspose for the check box is to count how many console did the 1st sales person have sold the console with and without controllers.... hmm can u guys understand what i'm trying to do? lol
 
I for one am just plain confused :confused:

Perhaps a sample of your DB might help us understand exactly what it is you are trying to achieve.
 
Presuming that each sale has an individual record that includes a checkbox to indicate the console was sold with a controller:

In the footer of your form, make a textbox with the control source:
Abs(Sum(checkboxfieldname))
 
sample.jpg

thats what i wanna do... hope u guys can understand it... lol thanks alot
 
Without knowing the structure of the form and its recordSet it is a little difficult to say much.
I presume you have the With Controller and Without Controller as an Option Group so you can't select both.
In any case recording both would be redundant since there are only two options.

If you place your count text boxes in the footer of the form the code I posted will work.

However if you want to use this technique on a per employee basis you would have to use a subform.
Otherwise use a DSum expression with a condition that the employeeID equalled the EmployeeID in the current record.
 
the sales details is a sub form of the employee form. i've tried the code u posted... the control source i typed ABS(sum(checkbox)) but it wont work... :(
 
Note that the Sum function acts on the RecordSet not the form's controls so the argument must be the name of the field in the Record Source query or table.
Use the name of the field bound to the With Controller checkbox.

The totals controls must be in the footer of the subform.
 
If this was excel I'd suggest a spinner control would be the way to go, so as it's not have a look at the attached DB. The form and control are unbound simply for speed of construction. You could bind the counter field to a field in your table.
 

Attachments

sigh i dun understand the things u guys said... hmm now i found another problem i didnt group the both checkbox together so the user can actually tick both of it.. and if i change it to the option group and i'm having two label names 1 is Yes and the other is No, do i still able to count the numbers of Yes? or No?
 
You could get just rid of one of them. Ticked for yes. Unticked for no.

To count the number of No records:
Count(*)+Sum(chkboxfield)

Count gives the total number of records. And because Yes = (-1) you will get the nos by adding the Sum to the count.
 

Users who are viewing this thread

Back
Top Bottom