473,779 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DSum / Sum for calculating Order Total

45 New Member
I am trying to create a food order system for a restaurant.

I have tried using both the DSum and Sum functions to calculate the total cost of an order. The total cost is a textbox on the form tblOrder (and a field in tblOrder) and the list of meals along with their costs are in the tblOrderDetail Subform (the columns in this form come fromt two tables - tblOrderDetails and tblItems).

I have been putting the DSum / Sum in the control soure property. With the expression builder I have tried:
DSum ( [tblOrderDetail Subform].Form![Cost] , [tblOrderDetail Subform].Form )
result: #error
=DSum([Cost],[tblOrder]) result: #name?
=DSum("Cost","t blOrder") result: #error
=DSum("[Cost]","[tblOrder]") result: #error

Sometimes I get #name? error, which i can solve by using a more lengthy description (not sure that's the right word) though all the internet examples only use one word in quotation marks, or i get #error which i can't solve at all.

I haven't specified a criteria as I wanted it to calculate the cost for all the items in that order

Both the table and the form are called tblOrder becasue I didnt change the name Access chose in the form wizzard

I am using Access 2000
Feb 6 '07
33 8245
NeoPa
32,577 Recognized Expert Moderator MVP
Instructions for creating the QueryDef (qryOrder).
  1. From the main Database window select Insert / Query.
  2. Click OK on Design View.
  3. Hit <ESC> to avoid adding a table.
  4. Select View / SQL View.
  5. Paste in the SQL posted earlier (Copied below).
  6. Select View / Design View.
  7. Close and, when prompted, select Yes to Save.
  8. Enter "qryOrder" (no quotes) as the name.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblOrder.OrderID,tblOrder.TableID,
  2.        tblOrderDetails.ItemID,tblItem.Cost
  3. FROM (tblOrder INNER JOIN tblOrderDetails
  4.   ON tblOrder.OrderID=tblOrderDetails.OrderID)
  5.      INNER JOIN tblItem
  6.   ON tblOrderDetails.ItemID=tblItem.ItemID
Feb 8 '07 #11
potassium flower
45 New Member
In reply to #7 and #8 and judging by 11# the SQL for the query is in the right place and the total cost textbox in the order form will give you the correct total if you close and re-open the form, just not immidiatly. Somehow I must have put the SQL in as code as well, which I have now deleted, and it works fine, thank you so much!!
Feb 9 '07 #12
potassium flower
45 New Member
Along a similar line I know I need to put .refresh somewhere so that the form always shows the most current total cost but I'm not sure what to attach it to and what code to put in front of it? Thanks again
Feb 9 '07 #13
NeoPa
32,577 Recognized Expert Moderator MVP
You will need a .Requery rather than a .Refresh.
I will try to have a look at this again to see where.
Feb 9 '07 #14
NeoPa
32,577 Recognized Expert Moderator MVP
Right, to know where to put the .Requery, we need to consider what is changing the data that this is worked out from.
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Cost]","qryOrder","OrderID=" & txtOrderID)
The code to do it would be :
Expand|Select|Wrap|Line Numbers
  1. Call Me.[Total Cost].Requery
It needs to be set up to trigger after any changes are made to the underlying data that effect the result.
Feb 9 '07 #15
potassium flower
45 New Member
Is that VB code that I should put on something like an after update event in the ItemID field of the subform? I'm just getting error messages or nothing at the moment and could do with a pointer?
Feb 10 '07 #16
NeoPa
32,577 Recognized Expert Moderator MVP
That's about right I think.
It does depend on which controls cause the result to change. You would need to add it to all of their AfterUpdate event procedures.
Feb 10 '07 #17
potassium flower
45 New Member
I've tried that but I can't get it to work, guess that's a bit more complex than I can manage at the moment, I'll just leave it to an update button I think, thanks so much for all your help :)
Feb 10 '07 #18
NeoPa
32,577 Recognized Expert Moderator MVP
That's alright.
Have you tried setting it on one control that you know causes the requery to be required, then testing it by changing the value in that control?
A step-by-step approach often works well in debugging.
Feb 10 '07 #19
potassium flower
45 New Member
I recon the control would be the ItemID because an addition of an Item is what requires the TotalCost to be recalculated. Thanks for the pointer.

However I keep getting a error saying "can't find the field "I" ' and the option to debug the line
Expand|Select|Wrap|Line Numbers
  1. Call Me.[Total Cost].Requery 
The VB code doesn't have an "I" in it so i don't know what to debug.
Feb 10 '07 #20

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

Similar topics

0
3353
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression, or maybe even DCount might be an alternative. I have tried numerous combinations, but with no apparent success. The DSum function relates to a subform (sfrmCost) with a text box (RefCost) which is intended to be the container for a total from a query (qryItems). The query has three number columns from the table (tblItems) of which I have an expression...
1
4803
by: Dalan | last post by:
I have tried both methods of using DSum and creating a Function to address summing some number columns, but to no avail. Since this has been a popular topic over the years, I'm sure I'll receive some guidance. This is related to Access 97 and involves my redoing a miscellaneous purchase and sales form. A main form (frmMain) is used that contains summary information of the item. I incorporated two continuous subforms (sfrmPurchases) and...
2
11594
by: Dalan | last post by:
I seemed to be having problems with structuring the use of NZ with a DSum expression. Having tried numerous variations of the expression without success, I'm asking for assistance. First some background (Access 97) - the DSum expressions are being used in grand total text boxes on the footer of a subform. And when viewing the subform in the linked main form the two grand total boxes display #Error if no entry had been made. Those with...
4
3014
by: John Baker | last post by:
Hi: I have a form, and wish to show on the form the current total for a single field on a table. I have set this up thus: =DSum(,!) in an unbound text field. These are correct field and table names. While the formulation is accepted by the system, nothing appears in the field and no results show up at all. I tried a number of combinations with no success. Can someone tell me what I am doing wrong? Thanks
1
4443
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have created a MainTable (and related form), which has an associated SubForm (popup) along with its underlying, separate Table. The tables' relationship is one to many respectively. The primary key
6
3664
by: pixie | last post by:
Hi. I'm having problems with the following DSum in my report footer. It gives me #Error when I run the report. I hope someone can help me out as I am at my wits end. What I am trying to do is to create a total budget which is revenues - expenses - expenses in-direct. Those controls are in the detail section of the report as groups. Here is the code. =DSum("","qrySummaryReport"," = 'Revenues'")-DSum("","qrySummaryReport"," = 'Expenses...
1
1717
by: Simon | last post by:
I am trying to have a button on my order form that will work out how much is outstanding on the order on the form i have the total value of the the order and also have text box that i want to dispaly the remaning amount. I store all the payments in a subform.
10
3786
by: Lisa | last post by:
In translating the formula for calculating lottery odds for various conditions into a Visual Basic Program, I have apparently missed something in that I get errors in the part of the calculation where the number of ways of failure (pFal) is calculated Both errors happen in the code section x1 = Draw - MatchesReq x2 = Field - Selections For Counter = 1 To (Draw - MatchesReq - 1) x1 = x1 * (Draw - MatchesReq - Counter)
3
2604
by: Bhujanga | last post by:
I have a field on a form that I'm trying to show the total of the invoices that have come in for the project. The ProjectID is field on the form which is in the forms primary table (ContractInfo). There is a child table called "Invoices" which is also has a ProjectID field that ties those records to the ContractInfo table, and of course it has a field for the InvoiceAmt. So in this ContractInfo form I have a text box and I'm using the following...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.