Full Version: Chk Box count
UtterAccess Forums > Microsoft® Access > Access Forms
waseemthonse
Hi,
There are around 12 check boxs in a form. I have a text box in the form end. The no of check boxes i selected to be shown in this text box. How i do it. Any Help?
Thanks
theDBguy
Hi,
That is the purpose of these checkboxes? You could try something like:
=Abs([chk1]+[chk2]+[chk3]+...+[chk12])
Hope that helps...
doctor9
waseemthonse,
You could loop through all of the controls in the form. Then, within the loop, check to see if the current control is a checkbox. If it is, check to see if it's value is TRUE. If it is, increment a counter.
When the loop finishes, the counter should contain the number of checkboxes that are marked as TRUE.
Hope this helps,
Dennis
waseemthonse
Dear Doctor9,
How i can i loop this.Can i get any sample db? which may help me..
Thanks
doctor9
waseemthonse,
ere's the basic idea:
CODE
    Dim ctl As Control, intCount As Integer
    
    For Each ctl In Me
        If ctl.ControlType = acCheckBox Then
            If ctl = True Then
                intCount = intCount + 1
            End If
        End If
    Next
    MsgBox intCount & " checked boxes."

Hope this helps,
Dennis
waseemthonse
Hi,
Thanks for quick response. But i have 12 check boxes and 1 text box on the form.Where i should put this code? Can i get detail procedure..
hansk
mike60smart
Hi
Are you saying you want to count the number of checkboxes that have a Tick (Is True)
mike60smart
Hi
sing theDBGuy's method see the attached
Click to view attachment
doctor9
waseemthonse,
o into the form's code module, and create a User Defined Function with the following code:
CODE
Function CountTrue() as Integer
    Dim ctl As Control
    
    For Each ctl In Me
        If ctl.ControlType = acCheckBox Then
            If ctl = True Then
                CountTrue = CountTrue + 1
            End If
        End If
    Next
End Function

Now you have a function that will count the number of "TRUE" checkboxes on the form.
In the control source for the textbox, use this as the ControlSource:
=CountTrue
Now the textbox will display the value returned by the function.
Each checkbox will need one line of VBA in it's AfterUpdate event which requeries the textbox, so its value is always up to date. You'll also need this code in the form's OnCurrent event:
Me.NameOfTextbox.Requery
That should do it, I think.
Hope this helps,
Dennis
waseemthonse
Hi Doctor 9 ,
It works Fine.But now i want if check box is already selected then it should not be visible. So how i can do that?
Thanks
Waseem
doctor9
Waseem,
That could have potential problems. Do you mean that once a person clicks on a checkbox, you want it to be marked as TRUE, and then the checkbox disappears entirely? When, exactly, would you want the checkboxes to become visible again? What if the user wants to undo a check, because they made a mistake?
If that's really what you want, you need to add another line of code to each checkbox's AfterUpdate event. For example, a control called "Check2" would be:
Private Sub Check2_AfterUpdate()
Me.NameOfTextbox.Requery
Me.Check2.Visible = False
End Sub
Remember, though, you'll probably need to loop through the checkboxes and set their visible property to TRUE at some point.
Hope this helps,
Dennis
waseemthonse
Hi, doctor9..
Actually i am preparing a db.Which is having 12 months staff salaries. When i select the person and then click the salary commond button, to pay, it should show all the 12 months. And if i paid then that month should not be visible.Only the months not paid should visible. So i can pay for the next month.
How i can do this? is there any other method?Any Idea?
Please help..
doctor9
waseemthonse,
I'm concerned that your table structure may be in need of Normalization if that's what these twelve checkboxes are for. You shouldn't have twelve separate fields for twelve months - that's known as a Repeating Group, and it can only lead to more and more work down the line.
Can you describe your database's table structure?
Dennis
waseemthonse
Hi,

tblstaff - have staff name,staff designation
tblmonth-have 12 months -jan,feb.mar etc
tblsal-staffID,Month and Amount.
I have a form with staff detail .This main form have subform1. When i open the form i shows on main form staff name.Subform shows 12 months,along the side 12 check box. when i select the check boxes,depending on that it shoudl count the no of months selected. based on that salary has to be counted. When i open the next time ,it should show only the balance months only..
I think i am missing something here.
How can i do this?
Please help me..
waseem
doctor9
waseem,
It looks like you're designing your database starting with the form. We need to get your data structure set up properly, and everything else comes after that.
Can you explain more fully what the purpose of this database is? That will help to set up the table structure and move forward. It looks like it's just keeping track of salary payments - is there any more that we should know before we continue?
Dennis
waseemthonse
Hi,
Yes it is tracking the salary payments. It should show 12 months period.if the person joined in febrauary,it should start the salary monythly from that Month.Whever it is paid, that month should not show next time. Only balance moth be shown in the form. I didn't start the designing the db. Once i get the idea only i can start. I need idea how we can do this? Please guide me and if any one have any sample db, please provide me,which may help me to understand easily...
Thanking You,
aseem
mike60smart
Hi
o going on what yoiu have said you need to do the following:-
Record details of Salary Payments made to an Individual/Employee
So you will need at least the following tables:-
tblEmployee
-EmployeeID - PK - Autonumber
-EmployeeFName
-EmployeeLname
tblEmployeePayments
-EmployeePaymentsID - PK - Autonumber
-EmployeeID - Number - Foreign Key (Linked to tblEmployee on PK EmployeeID)
-PaymentsID - Number - Foreign Key (Linked to tblPayments on PK EmployeeID)
tblPayments
-PaymentID - PK - Autonumber
-PaymentDate
-PaymentAmount
doctor9
Waseem,
The first thing is to look at the data you're going to work with, and try to break it down into logical groups. This is known as Normalization. The UA Wiki site has several good articles on Normalization, including this one.
So, based on what you've posted, I can see the following groups, which should have their own tables: Employees & Salary Payments. Here's one way to break those down into records:
tblStaff
StaffID [Primary Key, Autonumber]
strFirstName
strLastName
strDesignation
dteJoinDate
curSalary (This would be the person's yearly salary)
tblSalaryPayments
SalaryPaymentID [Primary Key, Autonumber]
intStaffID [Foreign key to tblStaff.StaffID]
dtePaymentDate
curPaymentAmount
With this setup you can have an unlimited number of salary payments for a staff member, across several years. You would use simple math to calculate things like:
* Monthly salary payment amount (yearly salary / 12)
* How much has been paid this year (sum the Payment Amounts for an employee for a given year)
* How many months of salary an employee will be paid this year (either 12, if the person joined before this year, or 12-the month the person joined)
* How much is yet to be paid this year (based on the months a person will be paid this year and the current month)
The best way to approach this, in my opinion, is to treat each of these pieces of information as a small problem, that can be broken down into easier-to-solve problems.
Also, keep in mind, these are suggestions I've made, based on what I've read in your posts - they aren't written in stone. I may not be aware of other aspects of the database that require attention. Or, I may have included things that aren't necessary (for example, I'm assuming you need to calculate the payment amounts, but your descriptions have never discussed that). Set up a table structure, put some test data in it, and see if you can create queries to display the information you need. If you get stuck, post what you're trying to do, what you've done so far, and where you're stuck.
I'd recommend starting a new thread for each new problem, so that it will get more attention from the experts here at UA. This will improve the chances of getting several ideas for help. After all, this thread is not really about twelve checkmarks on a form any more.
Hope this helps,
Dennis
waseemthonse
Hi,
It is exactly what i need.Can i get any sample DB , which may help me and give idea.
Thanks
mike60smart
Hi
Try creating the tables and then posting your Db to the Forum
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.