472,328 Members | 996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Getting the sum from a subform

I am trying to get a sum from a subform to show within a calculated control. Currently, I am using this expression:
=[RentalUnit subform].[Form]![NumOfRes]
But when I view my form, it shows only 2 occupants as opposed to the 12 that is expected. How do I get the sum of the NumOfRes to display?

Thanks!
Dec 2 '06 #1
13 15733
ADezii
8,832 Expert 8TB
I am trying to get a sum from a subform to show within a calculated control. Currently, I am using this expression:
=[RentalUnit subform].[Form]![NumOfRes]
But when I view my form, it shows only 2 occupants as opposed to the 12 that is expected. How do I get the sum of the NumOfRes to display?

Thanks!
'Here is code that I use to calculate values in a Sub-Form for a specific Item_ID
'in Inventory. This is a Calculated Control that exists in the Parent Form, For the
'Control Source Property of the Calculated Control.

Expand|Select|Wrap|Line Numbers
  1. =DSum("[Quantity]","tblLocSubLocQty","[MasterItemID]=" & Forms!frmHMAUMasterInventory!MasterItemID)
Dec 2 '06 #2
'Here is code that I use to calculate values in a Sub-Form for a specific Item_ID
'in Inventory. This is a Calculated Control that exists in the Parent Form, For the
'Control Source Property of the Calculated Control.

Expand|Select|Wrap|Line Numbers
  1. =DSum("[Quantity]","tblLocSubLocQty","[MasterItemID]=" & Forms!frmHMAUMasterInventory!MasterItemID)

ADezii,

I had the same problem. I don't understand your code above. What is "tblLocSubLocQty"?
Dec 22 '06 #3
ADezii
8,832 Expert 8TB
ADezii,

I had the same problem. I don't understand your code above. What is "tblLocSubLocQty"?
A Table that stores various Inventory values
Dec 23 '06 #4
A Table that stores various Inventory values

So [Quantity] and [MasterItemID] are fields in Table that stores various Inventory Values?

My ultimate question is: I have a subform attached to a main form in which both forms are linked through a Project ID field. When I change the Project ID field on the main form, only the records associated with the Project ID are shown on the subform.

I would like to sum a field in the subform and display that sum on the main form (perhaps in the footer). However, I want the sum of the subform fields to be only for the Project ID field shown.

Thoughts?
Dec 23 '06 #5
alpnz
113 100+
So [Quantity] and snip ...
I would like to sum a field in the subform and display that sum on the main form (perhaps in the footer). However, I want the sum of the subform fields to be only for the Project ID field shown.

Thoughts?
Have you considered using a listbox instead of a subform. And use the DSum aggregate function to find your value. It is quite a bit neater. This assumes you do not wish to edit anything in the subform.
What you can do is have another form called Edit "Sub date" E.g., which opens on a Double Click event for each line in the listbox. I realise this is going of topic, however the listbox does look neater on the form, and indeed is easy to name and refer to, if you wish to manipulate the list data.

DSum is the function you need to read up on to achieve the result you seek.
Dec 23 '06 #6
Have you considered using a listbox instead of a subform. And use the DSum aggregate function to find your value. It is quite a bit neater. This assumes you do not wish to edit anything in the subform.
What you can do is have another form called Edit "Sub date" E.g., which opens on a Double Click event for each line in the listbox. I realise this is going of topic, however the listbox does look neater on the form, and indeed is easy to name and refer to, if you wish to manipulate the list data.

DSum is the function you need to read up on to achieve the result you seek.

Unfortunately, I need to edit the subform.

I'm trying the following code:

Expand|Select|Wrap|Line Numbers
  1. DSum("[Source Code subform].[Form]![Circulation]", "[Source Code subform]", "[Source Code subform].[Form]![Camp Sched Proj ID] = Forms![Campaign Schedule]![Camp Sched Proj ID] = [Source Code subform].[Form]!Camp Sched Proj ID")
I've added the additional "=" because Access requests for one. I'm really lost here.
Dec 24 '06 #7
alpnz
113 100+
Unfortunately, I need to edit the subform.

I'm trying the following code:

Expand|Select|Wrap|Line Numbers
  1. DSum("[Source Code subform].[Form]![Circulation]", "[Source Code subform]", "[Source Code subform].[Form]![Camp Sched Proj ID] = Forms![Campaign Schedule]![Camp Sched Proj ID] = [Source Code subform].[Form]!Camp Sched Proj ID")
I've added the additional "=" because Access requests for one. I'm really lost here.
A lookup like DSum usually takes the form of
DSum("[the field you want summed]", "[In the table]", "[Where the field in the table equals]" -- "[An Object on the form you are referring to]")

So
Expand|Select|Wrap|Line Numbers
  1. DSum("[qty]","widgets","[widgetid] =" & Forms!widgetview![widgetid])
  2.  
Would give you the sum of [qty] in the widgets table where [widgetid] in the table equals [widgetid] on the form widgetview.
If widgetview is a subform then it is referred to as Forms!wadget.widgetview![widgerid].

Now Mary and many of the others that frequebt this site will quickly correct my syntax, as I am very adept at getting the quotes wrong etc, but try this and see what you get. Obviously insert your field and form names etc for your database.
Dec 24 '06 #8
A lookup like DSum usually takes the form of
DSum("[the field you want summed]", "[In the table]", "[Where the field in the table equals]" -- "[An Object on the form you are referring to]")

So
Expand|Select|Wrap|Line Numbers
  1. DSum("[qty]","widgets","[widgetid] =" & Forms!widgetview![widgetid])
  2.  
Would give you the sum of [qty] in the widgets table where [widgetid] in the table equals [widgetid] on the form widgetview.
If widgetview is a subform then it is referred to as Forms!wadget.widgetview![widgerid].

Now Mary and many of the others that frequebt this site will quickly correct my syntax, as I am very adept at getting the quotes wrong etc, but try this and see what you get. Obviously insert your field and form names etc for your database.
I'm sorry to be a pest about this, but it doesn't work. I get a syntax error "Expected:="

In any event, the exact code I'm using is:
Expand|Select|Wrap|Line Numbers
  1. DSum("[Circulation]","Source Code subform","[Camp Sched Proj ID] =" & Forms![Campaign Schedule]![Camp Sched Proj ID])
.

Is there something wrong with the code? The spaces in my form names? The fact I'm using a Subform? I've wrecked my brain here.
Dec 24 '06 #9
alpnz
113 100+
I'm sorry to be a pest about this, but it doesn't work. I get a syntax error "Expected:="

In any event, the exact code I'm using is:
Expand|Select|Wrap|Line Numbers
  1. DSum("[Circulation]","Source Code subform","[Camp Sched Proj ID] =" & Forms![Campaign Schedule]![Camp Sched Proj ID])
.

Is there something wrong with the code? The spaces in my form names? The fact I'm using a Subform? I've wrecked my brain here.
OK here is an example from a database I am working on.
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Count]","PakTrak","[PalletID] =" & [Forms]![frm_pcardboxed]![PalletID])
  2.  
Some things you will notice straight away. I do not have fields with multiple word names, And it is referring just to a form, not a subform, You should also note the use of bracketing, and quote marks, I was a bit rough the first attempt at answering this.

So what we need to do is sort out some values.

  1. Is [Circulation] a field in a Table. What is the name of the table.
  2. If So, is it a Number, not a text field.
  3. Is [Source Code Subform] a Table
  4. Is [Camp Sched Proj ID] a field in that table.
  5. Forms![Campaign Schedule]![Camp Sched Proj ID] does not refer to a subform, it is referring to a Form called [Campaign Schedule]
  6. What Form is [Campaign Schedule] a subform of.
If we can discover what each object above is, it will help decipher how the code should look.
Dec 24 '06 #10
OK here is an example from a database I am working on.
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Count]","PakTrak","[PalletID] =" & [Forms]![frm_pcardboxed]![PalletID])
  2.  
Some things you will notice straight away. I do not have fields with multiple word names, And it is referring just to a form, not a subform, You should also note the use of bracketing, and quote marks, I was a bit rough the first attempt at answering this.

So what we need to do is sort out some values.

  1. Is [Circulation] a field in a Table. What is the name of the table.
  2. If So, is it a Number, not a text field.
  3. Is [Source Code Subform] a Table
  4. Is [Camp Sched Proj ID] a field in that table.
  5. Forms![Campaign Schedule]![Camp Sched Proj ID] does not refer to a subform, it is referring to a Form called [Campaign Schedule]
  6. What Form is [Campaign Schedule] a subform of.
If we can discover what each object above is, it will help decipher how the code should look.
Great Thanks!
[*] [Circulation] is a field in a subform called [Source Code subform]
[*] [Source Code subform] is derived from a Table called [Source Code], so yes "Source Code subform" is a Table.
[*] [Camp Sched Proj ID] is a field in the [Source Code subform]/Table.
[*] [Campaign Schedule] is not a subform. It is a Main Form, and [Camp Sched Proj ID] is a field in [Campaign Schedule].

In short, [Campaign Schedule] is a Main Form and [Source Code subform] is a subform on the [Campaign Schedule] main Form.

Objective: Where Form and Subform [Camp Sched Proj ID] fields are equal, SUM the subform [Circulation] and print the value in a text field on the main form (possibly in the footer).
Dec 24 '06 #11
Great Thanks!
[*] [Circulation] is a field in a subform called [Source Code subform]
[*] [Source Code subform] is derived from a Table called [Source Code], so yes "Source Code subform" is a Table.
[*] [Camp Sched Proj ID] is a field in the [Source Code subform]/Table.
[*] [Campaign Schedule] is not a subform. It is a Main Form, and [Camp Sched Proj ID] is a field in [Campaign Schedule].

In short, [Campaign Schedule] is a Main Form and [Source Code subform] is a subform on the [Campaign Schedule] main Form.

Objective: Where Form and Subform [Camp Sched Proj ID] fields are equal, SUM the subform [Circulation] and print the value in a text field on the main form (possibly in the footer).

I just figured out the code! I typed:
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Circulation]","Source Code","[Camp Sched Proj ID] = Forms![Campaign Schedule]![Camp Sched Proj ID]")
into the Control Source of the Text Box and it worked! Instead of referring to the [Source Code subform], I referred to the table "Source Code".

Thanks for the example Aplnz, it really helped.
Dec 26 '06 #12
alpnz
113 100+
I just figured out the code! I typed:
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Circulation]","Source Code","[Camp Sched Proj ID] = Forms![Campaign Schedule]![Camp Sched Proj ID]")
into the Control Source of the Text Box and it worked! Instead of referring to the [Source Code subform], I referred to the table "Source Code".

Thanks for the example Aplnz, it really helped.
Coooool!!, To sum up, I always think of DLookups as an aggregate of the data, in the tables. There are people frequenting this site far more qualified than myself to give you a more coherent explanation, dark shady types, who when you speak their names, you must whisper .... :-) in reverance ....
Don't suppose you know how to Consolidate 4 reports into one report, so that I can send it on one Email?.
Dec 27 '06 #13
Coooool!!, To sum up, I always think of DLookups as an aggregate of the data, in the tables. There are people frequenting this site far more qualified than myself to give you a more coherent explanation, dark shady types, who when you speak their names, you must whisper .... :-) in reverance ....
Don't suppose you know how to Consolidate 4 reports into one report, so that I can send it on one Email?.
Reports huh? That's my weak spot. I'm great at queries, just learned Forms but I've never created a Report before. Sorry. I'll be posting some Report questions soon, because I need to generate a few myself.
Dec 27 '06 #14

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

Similar topics

0
by: Josh C. | last post by:
Hello everyone. I'm a bit of an Access newbie, so please bear with me. Please go to http://www.dumoti.com/access/ to view the database - 536kb....
1
by: xmp333 | last post by:
Hi, I have a form that is designed as a data sheet view. Attached to this is a subform with some VB code. When the user clicks on a row, the...
1
by: xmp333 | last post by:
Hi, I have a data sheet with a subform; each time the user clicks on the "+" to show the subform, I want some code to run. I tried attaching...
1
by: kkrizl | last post by:
I have a form that displays general information about an alarm permit location. There's a subform that shows detailed information about burglar...
5
by: Thelma Lubkin | last post by:
I have a form/subform with the common one-to-many relationship. The form allows user to display records and move to other records via the selector,...
1
by: sparks | last post by:
I have a form/table with an autoid it is linked to a table/form with and ID as a 1 to many. Under this form/table I need another table with many...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a...
8
by: Christina123 | last post by:
Currently working with Microsoft Office 2000 and whatever version of Access came with that. I am developing a database to track the comings and...
8
by: Neekos | last post by:
I have a form called frmPaxInfo, and on this form is a subform called subfrmPaxInfo. This subform (which is filtered by cabin) contains the...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.