Go Back   PCMech Forums > Help & Discussion > Software Discussion & Support

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 09-28-2006, 12:56 PM   #1
Kickin' it
Staff
Premium Member
 
Alaron's Avatar
 
Join Date: Jan 2002
Location: USA
Posts: 7,723
Send a message via AIM to Alaron
Sum Function in Access 2003

Hello all. I'm having a bit of trouble with Access's Sum function.

I have a Form for distributor orders with a couple of subforms on it. One of the subforums shows the items that were ordered with fields for Model, Number Ordered and Price.

I want to create a box next to that subform that shows the order total.

I set up an expression in the control source to take the sum of Price * Number ordered. It looks like this:

=Sum([Ordered Items].Form!Num_Bikes*[Ordered Items].Form!Price)

But it comes back with an error.

If I leave it as: =[Ordered Items].Form!Num_Bikes*[Ordered Items].Form!Price , The box will show the total for one model at a time, but I need a complete total.

If anyone has any suggestions about what I'm missing, I would appreciate it.

Last edited by Alaron; 09-28-2006 at 01:06 PM.
Alaron is offline   Reply With Quote
Old 09-28-2006, 01:27 PM   #2
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Do you mean that the subform shows one model at a time, but you want the sum to be over all models (that is, over all of the records in the subform)?
doctorgonzo is offline   Reply With Quote
Old 09-28-2006, 01:59 PM   #3
Kickin' it
Staff
Premium Member
 
Alaron's Avatar
 
Join Date: Jan 2002
Location: USA
Posts: 7,723
Send a message via AIM to Alaron
There are multiple models in the subform. The Order Total box will only show the total for one record at a time.

I attached a screen shot of the form.

The order total is only showing 12000 for the 3 M300 bikes. I would like it to show $29990 for the total of all 5 bikes.

Thanks.
Attached Images
File Type: jpg access1.JPG (68.2 KB, 53 views)
Alaron is offline   Reply With Quote
Old 09-28-2006, 02:02 PM   #4
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
That's what I thought: there are separate records for each model. You aren't going to be able to do this using VBA functions, or at least I don't know of a way to do this. You will need to create a query that will sum up everything for each order ID, and then display that in the box. Something along the lines of "SELECT SUM(Num_bikes*Price) FROM Order WHERE OrderID=[the order ID]". Of course, replace the table and field names with what you have in your database.

I would put this in code and set it to update every time the subform is updated.
doctorgonzo is offline   Reply With Quote
Old 09-28-2006, 03:09 PM   #5
Kickin' it
Staff
Premium Member
 
Alaron's Avatar
 
Join Date: Jan 2002
Location: USA
Posts: 7,723
Send a message via AIM to Alaron
Thanks for the help. I feel like I'm closer.

I created a query that multiplies Num_Bikes by Price and puts the value in a field named Total. The query runs and creates the correct total but its still for just one model at a time. I can't seem to get all the bikes from one particular ID to sum up.

I then went back to my Order Total box in the Order Form and added a new control source from that query. But now when I check the form, it says "#Name?"

Any ideas?

The attachment shows first the query setup and then the expression for my Order Total.
Attached Images
File Type: jpg Access2.JPG (65.1 KB, 42 views)

Last edited by Alaron; 09-28-2006 at 03:19 PM.
Alaron is offline   Reply With Quote
Old 09-28-2006, 03:26 PM   #6
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
I don't think that will work, as it doesn't reference the particular order number that you are dealing with.

Like I said, I would put this in VBA code using ADO to open up that query, read the value determined by the query, and then display it in the box. Setting the query up as the control's data source doesn't seem to work well.
doctorgonzo is offline   Reply With Quote
Old 09-28-2006, 03:40 PM   #7
Kickin' it
Staff
Premium Member
 
Alaron's Avatar
 
Join Date: Jan 2002
Location: USA
Posts: 7,723
Send a message via AIM to Alaron
I'm not familiar with ADO, so I suppose I'll leave well enough alone. This is for an introductory MIS course I'm taking, so that is out of our scope.We had been working only on basic Design View and Wizards rather then actual code. I was just trying to figure it out from personal interest. Thanks for all the help DrG. I'd be grateful for a walkthrough if you can though.
Alaron is offline   Reply With Quote
Old 09-28-2006, 03:46 PM   #8
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
This is very rough kinda pseudo-code, but this is what it would entail. I would change the control where the data will appear to a label, then do something like this in the "On Change" or "On Update" event for the subform:

Code:
Dim recBob as ADODB.Recordset
Set recBob = new ADODB.Recordset
recBob.Open "SELECT SUM(Num_bikes*Price) FROM Order WHERE OrderID=" & Me.[OrderIDInfo], CurrentProject.Connection, adOpenStatic, adLockReadOnly
Me.[LabelForData].Caption=recBob.Fields(0).Value //Note, this may have to be changed to get the right number
recBob.Close
set recBob=Nothing
doctorgonzo is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2003 Rights/folder access achilipepper Windows Legacy Support (XP and earlier) 5 04-04-2005 04:35 AM
Office 2003 pro question quickstart Software Discussion & Support 2 07-25-2004 03:49 PM
Advanced Microsoft Exchange 2003 questions (POP3/SMTP/SPAM) gicio Internet, Web Applications, & The Cloud 1 05-13-2004 09:37 PM
Cannot access website but can from work Iman74 Internet, Web Applications, & The Cloud 8 11-07-2003 01:48 PM
Security Advisory: Alcatel SpeedTouch ADSL Modem is Insecure! Statica Networking & Online Security 0 04-10-2001 11:57 PM


All times are GMT -5. The time now is 09:26 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2