473,769 Members | 2,124 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 #1
33 8243
Rabbit
12,516 Recognized Expert Moderator MVP
What's the meta data for the tables? i.e. The fields of the table and type of data it holds.
Feb 6 '07 #2
potassium flower
45 New Member
Expand|Select|Wrap|Line Numbers
  1. tblOrder
  2. OrderID Autonumber
  3. TableID Number
  4. Total Cost Currency
Expand|Select|Wrap|Line Numbers
  1. tblOrderDetails
  2. OrderDetailsID Autonumber
  3. OrderID Number
  4. ItemID lookup
  5. (and other records that I dont think are relevant)
Expand|Select|Wrap|Line Numbers
  1. tblItem
  2. ItemID Autonumber
  3. Cost Currency
  4. (and other records that I dont think are relevant)
Feb 6 '07 #3
NeoPa
32,573 Recognized Expert Moderator MVP
Check out this link (Normalisation and Table structures). It explains why storing the calculated value is not a good idea.
Are you sure the tblItem table doesn't have a name field of some form? Hard to think this could be irrelevant.
Ignoring the updating of the [Total Cost] field, you will need a QueryDef (saved query) called something like qryOrder, whose SQL is :
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
In the Control Source of your Total Cost control you would need :
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Cost]","qryOrder","OrderID=" & txtOrderID)
Feb 7 '07 #4
potassium flower
45 New Member
Thanks, not storing the Total Cost makes sense and the code will now calculate the Total for that order. However I have added a button for refreshing the form, so that you dont have to open and close the form to get the correct total-

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command18_Click()
  2.  
  3. DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
  4.  
  5. End Sub
But when I click it a message box appears "Compile Error: Expected: Case" and tblOrder is highlighted from the first line of the code for calculating the total cost-

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
Im not sure if that means an error somewhere or that I'm going about refreshing the wrong way?
Feb 8 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
You are getting an error because you are trying to use straight SQL code as visual basic code.

Either have the SQL in a query and run the query from code or use a DoCmd.RunSQL "SQL Code Here". Quotes included.
Feb 8 '07 #6
NeoPa
32,573 Recognized Expert Moderator MVP
In this case, referring back to the instructions in post #4, you need to save this SQL into a QueryDef called qryOrder. Otherwise the DSum() function cannot work.
Feb 8 '07 #7
NeoPa
32,573 Recognized Expert Moderator MVP
Let us know if this makes sense to you.
If necessary we can break it down into easier to follow steps.
Feb 8 '07 #8
potassium flower
45 New Member
I've put it around the

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
and the same error appears, is that the right place?
Feb 8 '07 #9
Rabbit
12,516 Recognized Expert Moderator MVP
That's the wrong place, you put it around the select statement. You're going to have to put the Select SQL statement on one line.
Feb 8 '07 #10

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
3013
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
4442
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
3663
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
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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
9860
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...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
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
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3955
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
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.