Code to show the number of how many checkbox was checked

M

Milindra

I want to create five checkboxes on my form and one
textbox. Then, when I click on checkbox it will
automatically add up the number that I checked on the
checkboxes.

For example: If I checked two boxes, it will automatically
show on the textbox as 2

Thank you in advance,
Malindra
 
D

dan artuso

Hi,
In order to do this you will have to name your checkboxes accordingly.
For my example I have named them chk1, chk2, chk3 and so on.
You can replace 'chk' with anything you like, just make sure they end with 1,2,3,4,5

Put this function in your form's code module:

Private Function CountCheck() As Integer
Dim i As Integer

For i = 1 To 5
If Nz(Me("chk" & i), 0) Then
CountCheck = CountCheck + 1
End If
Next
End Function

Then in each of your checkboxes After Update event, put this:

Me.txtTotal = CountCheck()

Replace txtTotal with the name of your text box.
 
M

Milindra

Thank you for your kindness. I did everything like what
you said, but it still didn't work. It pop up an error
code on the Checkbox code under Afterupdate(). It seems
doesn't know the function that I created om the module. Is
there any suggestion.

Thank you,
Minlindra
 
D

dan artuso

Did you put the function in the form's code module or a standard module?
It should go in the form's code module
 
M

Malindra

It's working now. It was my fault. I didn't read it clear
where to put CheckCount function. I really appreciate.

Malindra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top