Problem:How to get Grandtotal of subtotal if the source is in unbound textbox

phatus

Registered User.
Local time
Today, 11:29
Joined
Nov 10, 2010
Messages
100
hi all,

good day i have a problem in my data base getting the grandtotal of my subtotal...
i dont have a TOTAL fields in my Table... my TOTAL in my form is Unbound in my form this is the code in my unboundtextbox total
First Yr
Code:
=[first yr male]+[first yr female]
Second Yr
Code:
=[second yr male]+[second yr female]
Third Yr
Code:
=[third yr male]+[third yr female]
Fourth Yr
Code:
=[fourth yr male]+[fourth yr female]
Total Enrolment
Code:
=[first yr male]+[first yr female]+[second yr male]+[second yr female]+[third yr male]+[third yr female]+[fourth yr male]+[fourth yr female]
so example i have 3 schools it means i have 3 Total Enrolment
what code i will make to total the 3 schools to get the grandtotal

i tried this code but it dont work

Code:
=Sum([first yr male]+[first yr female]+[second yr male]+[second yr female]+[third yr male]+[third yr female]+[fourth yr male]+[fourth yr female])
pls help me.. thank you. its a continues form...
 
Last edited:
Hopefully you don't actually have fields in your table like [first yr male], [first yr female], [second yr male], etc.!

Are these calculated fields in a query, or calculated controls on a form?
 
Hopefully you don't actually have fields in your table like [first yr male], [first yr female], [second yr male], etc.!

Are these calculated fields in a query, or calculated controls on a form?
There is, in my table the fields are only Name of School, first yr male, first yr female, second yr male, etc.! there is no total fields of male and female and no grandtotal of the 3 schools..
any idead how to do this sir.... you thought me that total should not store in the table.... now im having a problem getting the grand total ^_ ^

by the way the grandtotal will only appear in the report..

example in the from 3 school with the following total enrolment 100, 200 and 300 respectively

in the report will appear Grandtotal enrolment 600.... the my problem is my source is unboundtextbox its the TOTAL in the form i will add...

hope you get it sir.. thank you again...
 
Last edited:
Here is some partial code from a report that I developed today. Each text box is a subtotal that is then aggregated into a grand total (Text36). Note the use of Dcount to generate a subtotal with a query.

Also, as Beetle wrote "Hopefully you don't actually have fields in your table like [first yr male], [first yr female], [second yr male], etc.!"

Code:
    Me.Text32 = DCount("q12", "ConsistencyMain", strFilterCriteria00 & " AND " & strFilterCriteria01 & " AND Q12")
    Me.Text34 = DCount("q13", "ConsistencyMain", strFilterCriteria00 & " AND " & strFilterCriteria01 & " AND Q13")
    Me.Text36 = Me.Text12 + Me.Text14 + Me.Text16 + Me.Text18 + Me.Text20 + Me.Text22 + Me.Text24 + Me.Text26 + Me.Text28 + Me.Text30 + Me.Text32 + Me.Text34
 
That sound's like a very de-normalised table structure.

You Table should probably look like;

TBL_Student
StudentID (PK)
StudentBrthDt
StudentGiveName
StudentFamName
StudentGender
StudentYrLvl

... and even that could be further normalised
 
im sorry im just a beginner in ACCESS my table objective is to get the total enrolment...
that's why my fields are:
Stdschool for example i have 3 school namely school 1, 2 & 3
StdfirstyrM
StdfirstyrF
StdsecndyrM
StdsecondyrF
StdthirdyrM
StdthirdyrF
StdfourthyrM
StdfourthyrF

sa you can see theres no total field sir...
to get the total of male and female i make this code to my unboundtextbox

Code:
=[StdfirstyrM]+[StdfirstyrF]
and the rest to fourth yr.. thats per form...

and i will total all first yr to fourthyear and here i my code:
Code:
=[StdfirstyrM]+[StdfirstyrF]+[StdsecndyrM]+[StdsecndyrF]+[StdthirdyrM]+[StdthirdyrF]+[StdfourthyrM]+[StdfourthyrF]
this is the total sum of male and female from 1st yr to 4th yr... and this will be the source to my grand total...

Grandtotal=totalenrolment sch1 + total enrolment schl2 + total enrolment schl3
Here is some partial code from a report that I developed today. Each text box is a subtotal that is then aggregated into a grand total (Text36). Note the use of Dcount to generate a subtotal with a query.


Me.Text36 = Me.Text12 + Me.Text14 + Me.Text16 + Me.Text18 + Me.Text20 + Me.Text22 + Me.Text24 + Me.Text26 + Me.Text28 + Me.Text30 + Me.Text32 + Me.Text34
is this what you mean i will put a unboundtext box in my report to sum up all the 3 schools total.
Code:
Me.Grandtotal= Me.school1 + Me.school2 + Me.school3
i forget they are all calculated controls on a form

i have attached a sample of my database.. thank you
 

Attachments

Last edited:
Well I'm not completely sure what you're modeling here because all you have is one table with some school names and some values for total males and females for each year. You don't seem to be tracking any actual student information, so I'm not sure you even need a database. What you have here could just be handled in a simple spreadsheet.

However, if you are going to use a relational database, then you should use it relationally. I have reattached your database. I left your original objects (table, form and report) but added new ones to demonstrate how entities are modeled in a relational database like Access. In this case you are modeling Schools and Enrollment, which are two separate entities and therefore need two separate tables. These tables have a One (Schools) to Many (Enrollment) relationship.

The new form uses a Main Form/Sub Form setup, with the schools info in the main form and the enrollment info in the sub form. Finally, the new report uses grouping and calculated text boxes to get the totals you want.

Hopefully this will give you a better understanding of the proper design practices when working with Access.
 

Attachments

Well I'm not completely sure what you're modeling here because all you have is one table with some school names and some values for total males and females for each year. You don't seem to be tracking any actual student information, so I'm not sure you even need a database. What you have here could just be handled in a simple spreadsheet.

Actually i have 3 table connected them in Tabcontrols using relationally
tblschooldata - first tab
tblenrolment - secondtab
tblagprofile - third tab

my main focus is how can i add all the total to make the grand total appeared in my report thats why i only put the table enrolment in my sample sir..
to make it easier for me on how or what im going to put in the grandtotal unboindtextbox formula...

i will look at it sir but if you can still modify my sample table with the original table it very well appreciated sir.. because this is the most important part in my database because im incharge in reporting the Grandtotal...
 
sir beetle im corrently working my own sample database based on your modified database... my data in secondary consist of 198 schools and 861 school in elementary.. i send you mail private here in this forum.. hope you read it and get some response...

this forum help me a lot...

thank you very much....
 
Sir Beetle im having trouble in my report..
i added a table named tblpreschl which consist of the following field School ID, Male, Female
i cant put it in enrolment table for the reason that pre-school is not included in the grand total... i notice when i put the pre-school data in tblenrol pre-school is also included in the total
Code:
=sum([Male])
and
Code:
=sum([Female])
so i make a separate table for pre-school enrolment data...

the formula i make for pre-school is
Code:
=[Male_tblpreschl]+[Female_tblpreschl]
its only a total...

when im going to add them in grand total..
name of unobundtextbox of total is
the pre-school is being multiplied by 6 because i think in per school theres grades 1-6....

i tried this formula in my pre-school grandtotal
Code:
=sum([Male_tblpreschl])
for male and
Code:
=sum([Female_tblpreschl])
for female and to get the grand total... =[txtmale]+[txtfemale]

it is based in my report.
can you help me regarding this matter..

attached here is the sample of my database hope you will look at it to see clearly what i mean.
untitled-9.jpg

thank you very much....
 

Attachments

Last edited:
i cant put it in enrolment table for the reason that pre-school is not included in the grand total... i notice when i put the pre-school data in tblenrol pre-school is also included in the total
so i make a separate table for pre-school enrolment data...

No, you don't want to do that. Tables are intended to represent real world entities. Within the context of your database, pre-school is not it's own separate entity. It's just an attribute of the grade levels entity (in other words, it's just a grade like all the others). When you want to limit or restrict the results you get from a table, you don't split some of the data out into a separate table, you use a query.

I do think it would be a good idea to add a table for grade levels, to eliminate data entry mistakes and to make sorting the grades easier (because you can sort by GradeID rather than by the description). I also think you should add a table for Districts for the same purposes, as well as accounting for the future possibility of re-districting. These tables would then be related to tblEnrol and tblRecord respectively, and you use combo boxes on your forms to select the Grade Level and the District.

There is also another advantage to this approach. For example, you have a form with two subforms. One of the subforms is for pre-school enrollment and the other is for elementary (or primary) enrollment. The correct way to handle this is to create queries for each subform. One query returns only pre-school records and the other returns only elementary records, but it all comes from the same table. Also, since you are using a combo box to select the grade level, the combo box can easily be set up so that (for example) the users can only select grades I - VI when entering new records in the elementary enrollment subform. You could apply this same concept to a secondary enrollment subform if you had one.

In your report, since you need different totals for pre-school as opposed to the other grade levels, one approach is to use the Domain function DSum with some criteria to return the sums for only the grade levels you want. For the sub-totals for each school you restrict the results by both grade level and SchoolID, and for the grand totals you restrict the results by grade level only. The report itself should also be based on its own query, because the result set you want for the report is not the same as the result set you want for the forms. It's basically the same data but it's put together a little differently to make the report look the way you want.

As far as getting your subforms to look like your image, you need to make them continuous forms, but you need to design them correctly so they display the way you want. The controls need to be laid out next to each other all in one row, left to right, and the height of the form itself should be just slightly more than the height of the controls.

I have re-attached another copy of your application so you can see the application of these methods. By the way, IMO you should not use spaces in your field names, so I took the liberty of correcting that for you.:)
 

Attachments

By the way, IMO you should not use spaces in your field names, so I took the liberty of correcting that for you.
smile.gif
thank you for this, my database need a lot of revision..

i understand a lot sir.. thank you again...
 

Users who are viewing this thread

Back
Top Bottom