Adding 2 fields together - you'd think it would be easy, wouldn't you?

bodhi23

Registered User.
Local time
Today, 14:04
Joined
Dec 22, 2004
Messages
26
Ok, I'm absolutely positive I'm missing something totally simple here... Someone give me a clue...

I have a database whereby I track academic performance of students in our program. I am trying to use last year's table to calculate how many hours each student earned during all three semesters.

In many cases, students did not enroll in all three semesters, so I am dealing with Null values in many of the fields. The easiest way would be to do something with the Nz function such as follows:

HrsEarnedLastAY: Sum(Nz([HrsEarnedFall],0)+Nz([HrsEarnedSpring],0)+Nz([HrsEarnedSummer],0))

But what I am getting is the numbers in a string! Say, a student earned 12 hours in the fall, and 10 hours in the spring, and didn't attend at all in the summer. The answer I'm getting in the calculated field is 1210, rather than 22. I've tried about 50 permutations of the above expression and I truly can't see why it isn't adding the fields together... I have also tried this with parenthesis around each Nz: (Nz([HrsEarnedFall],0)) , same result.

The Sum function does not recognize Null fields, but I thought I could use the Nz function to account for that. If I can't use Nz with Sum, how the heck do I add these numbers?

What I need to do is create a table with these hours totaled, and then update my main table from it. I could conceivably add the fields together in a report, but then I don't have any way to update my main table other than simple data entry.

I really do not want to have to go back into almost 700 records and add in zeros in multiple fields just because I'm missing something stupid.

You'd think an application as powerful as Access would be able to add 2+2 and get 4...
Any help would be most appreciated...
 
Are all three fields in the same record? Have you tried dropping the Sum() and:
(Nz(CInt([HrsEarnedFall]),0)+Nz(CInt([HrsEarnedSpring]),0)+Nz(CInt([HrsEarnedSummer]),0))
 
With names like last years table and separate fields for each semester and the need to store the total hours leads one to conclude that you've approached Access as a spreadsheet. Were you to normalise the db and data then you would not have the problem summing the hours.
 
RuralGuy:
I tried your version of the expression, and without Sum, got an invalid use of Null function error. When I removed the totals line, the expression works for the records that contain hours in each field, but returns #Error for anything that had Null values in one or more fields...

Rich:
I do come from a spreadsheet background, and my experience with Access is only slightly above "beginner". Help files are pretty useless for the problems I'm coming across for the most part. Though I do occasionally find useful information in this forum...

The name of the table I'm currently using is actually tbl_20052006Students. I have to push out the prior year's data because I have to continue for the current academic year but still use the previous year's data to report to the Dept. of Education. Internal reporting needs require that semester hours earned be kept separately instead of a running total in a single field, as I often have to report on student enrollment status by semester over the course of an entire year.

The database I'm using is one created by a predecessor in my position, I have plans to start over with improvements - in the planning stages now, actually.

How would you suggest I reconfigure to get the answers I need?
 
Last edited:
RuralGuy:
I played around with the expression you gave me and this:
(CInt(Nz([HrsEarnedFall]))+(Nz([HrsEarnedSpring]))+(Nz([HrsEarnedSummer])))
worked perfectly.

Thank you.

Rich: I am still interested to hear your thoughts on database configuration...
 
Hello:
The reason this is happening is because you probably have your DataType setting in your table set to Text, it must be Number. I verified this, and what you state above happens in fields where the DataType is set Text and that field contains numbers.
'
Regards
Mark
 
mhartman is almost correct, what actually was happening is that the Nz function does infact return a text field and although text numbers can be summed, not however by using + which text treats as a concatenation.
A way round this is to use Val(Nz(.....

Brian
 

Users who are viewing this thread

Back
Top Bottom