473,382 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to sum a form's controls and display the result in a control?

sueb
379 256MB
I have a form the displays some 3,1 decimal fields from my table, and I want to sum these fields and display them in an unbound control. I've tried putting the addition statement in the .Control Source property:

Expand|Select|Wrap|Line Numbers
  1. =[Discharge Rounds]+[ICU Rounds]+[NICU Rounds]+[Peds Rounds]+[Palliative Care]+[Weekly 10-Day]+[Peri-Natal Substance Abuse]
but nothing shows up in the control.

I tried making each field re-calculate AfterUpdate:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Calculate_Total_Hours()
  2.     Me.[Total Hours] = Me.[Discharge Rounds] _
  3.                     + Me.[ICU Rounds] _
  4.                     + Me.[NICU Rounds] _
  5.                     + Me.[Peds Rounds] _
  6.                     + Me.[Palliative Care] _
  7.                     + Me.[Weekly 10-Day] _
  8.                     + Me.[Peri-Natal Substance Abuse]
  9. End Sub
  10.  
  11. Private Sub Discharge_Rounds_AfterUpdate()
  12.     Calculate_Total_Hours
  13. End Sub
  14.  
but, again, nothing.

What am I doing wrong? I thought this, at least, would be straightforward in Access...
Mar 15 '11 #1

✓ answered by NeoPa

Is it possible any of the fields (in the query) that are used in the calculation may have no values in them?

In that case the field results would be Null, thus converting any calculation based on them to Null.

Try using the following form for your query :
Expand|Select|Wrap|Line Numbers
  1. TotalHours: Nz([Discharge Rounds],0)+Nz([ICU Rounds],0)+...

7 1839
TheSmileyCoder
2,322 Expert Mod 2GB
You could always take the approach of summing the fields within your query, and then binding that to a textbox.

If you want to go with the function you have defined, I think you should use the CONTROL NAMES instead of the FIELD NAMES, and make sure your control names are NOT equal to your field names, or access can get confused. I know this has caused me grief before, but I've never really investigated it fully.

Also make sure you have OPTION EXPLICIT set at the top of your module.
Mar 15 '11 #2
sueb
379 256MB
Okay, I tried putting an expression in the query (and removing the AfterUpdate code), but still nothing shows up in my control. In fact, nothing shows up in the datatable view, either. Here's the expression in the query:

Expand|Select|Wrap|Line Numbers
  1. TotalHours: [Discharge Rounds]+[ICU Rounds]+[NICU Rounds]+[Peds Rounds]+[Palliative Care]+[Weekly 10-Day]+[Peri-Natal Substance Abuse]
Mar 16 '11 #3
NeoPa
32,556 Expert Mod 16PB
Is it possible any of the fields (in the query) that are used in the calculation may have no values in them?

In that case the field results would be Null, thus converting any calculation based on them to Null.

Try using the following form for your query :
Expand|Select|Wrap|Line Numbers
  1. TotalHours: Nz([Discharge Rounds],0)+Nz([ICU Rounds],0)+...
Mar 16 '11 #4
sueb
379 256MB
Do you mean that, if one of two fields is null, Access can't perform addition on them?
Mar 16 '11 #5
sueb
379 256MB
Well, @NeoPa, that did it! I'm constantly amazed by Access' ability to un-intuit (new word there, in honor of this most wondrous of applications) even the simplest functions. I mean, who doesn't think that "two plus nothing still equals two"?

Thank you, NeoPa, for remembering how it is for we noobs, and being able to convey that which you learned so long ago that you've practically forgotten it! :-)
Mar 16 '11 #6
NeoPa
32,556 Expert Mod 16PB
Always a pleasure Sue :-)

I suggest you stop thinking of Null as anything close to zero though. It is no more zero than it is 13,425 or any other numeric value. It is less close to zero than infinity is. It is an absence of a value. It is a place-holder for what maybe sometimes is a value but this time isn't. It doesn't even have a type of numeric. It is merely there to indicate nothing is there.

I hope that explanation makes working with Nulls in future a more intuitive experience for you. I'm afraid Access (or Microsoft if you prefer) didn't get anything wrong here. The misunderstanding does not come from that quarter. If you look in Help for Null you will find :
Null

A value indicating that a variable contains no valid data. Null is the result of an explicit assignment of Null to a variable or any operation between expressions that contain Null.
Mar 16 '11 #7
sueb
379 256MB
Yes, of course, you're right about Null, NeoPa. Thanks for the explanation!
Mar 16 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steve McLellan | last post by:
Hi, I have an MDI application. Child forms have control boxes with min/max/restore buttons. As well as using the MDIList menu property to choose between forms, I have a representation of the...
2
by: Richard Holliingsworth | last post by:
Hello: Thanks for reading this. I would like to make some on the fields on my Access 2002 Form updatable only by an admin (or privilidged user). I can't find any references to this in the...
1
by: Greg Brady | last post by:
How to display result set in random order? Thanks.
0
by: William F. Zachmann | last post by:
A web site that will run on Windows Server 2003 and IIS 6.0 needs to provide three levels of access, one for the public and two others for two levels of subscribers. This is a port of a prior site...
1
by: Aparna Rege | last post by:
Hi, I am having trouble with a tab control. All the fields on the form are data bound and are spread over two tabs of a tab control. I have placed a Clear button with the code to clear all the...
1
by: paavani krama via .NET 247 | last post by:
(Type your message here) I am using two forms.From the first form i need to getinformatiom.After performing necessary calculations,the resultshould be displayed in the 2nd form.i am storing the...
11
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in...
6
by: johntarr | last post by:
I hope I am not asking about something that has been done before, but I have searched and cannot find an answer. What I am trying to do is to run a query, and then perform some logic on the...
6
by: gunanallasamy | last post by:
hi Folks, i came across a situation for which still i couldn't get a solution. i have table like below(some other columns are also there) option value -------...
1
by: martin DH | last post by:
Hi all, I think I'm just blanking on some basic concept here...in Access 2003 on XP. Here's the process - the user enters an ID number, clicks the command button, and the other two fields are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.