473,396 Members | 1,914 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,396 software developers and data experts.

Forms: Count & SUM in VBA Access

Hello all,

Before you read my question, I would advise you to visit the Image-Link.

The image-link shows 4Tables - its field, Primary, Foreign Keys, Relationships. The bottom of the Image, it is a Query (TransQ).

My question,

I am using a listbox to preview the following Count Code:

Expand|Select|Wrap|Line Numbers
  1. Me.listDetailsBox.RowSource = "SELECT ItemID, Count(TransQty) AS QtySold FROM TransQ GROUP BY ItemID ORDER BY Count(TransQty) DESC"
Data Example:
Expand|Select|Wrap|Line Numbers
  1. ItemID          Qty     Unit$      Total$
  2. Item200         2          $1            $2
  3. Item200         1          $1            $1
  4. Item200         5          $1            $5
Output using the code above:
Expand|Select|Wrap|Line Numbers
  1. ItemID          Count(TransQty)
  2. Item200                        3
The code's output only refer to 3 transaction, rather than the total quantity for all transaction which belongs to the ItemID. Is there anyway to make it that way?

The output should be
Expand|Select|Wrap|Line Numbers
  1. ItemID          Count(TransQty)
  2. Item200                        8
Aug 28 '09 #1
3 3461
Delerna
1,134 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Me.listDetailsBox.RowSource = "SELECT ItemID, Sum(TransQty) AS QtySold FROM TransQ GROUP BY ItemID ORDER BY Count(TransQty) DESC"
  2.  
count counts the number of rows in that group.
You have 3 rows

sum totals all the values in a field in that group
The sum of those three rows is 8
Aug 28 '09 #2
Thanks a lot. Really thanks a lot.

I have a further question. For this question, I am not really sure where to start to build the code. I want to have a Top 10 List. For an example, Top 10 Best-Selling Item. How can i limit the result to only display 10 or less? What type of Control-Box should i use - listbox?

if listbox, this is my RowSource code.
Expand|Select|Wrap|Line Numbers
  1. dateSource = "SELECT ItemID, Sum(TransQty) As QtySold FROM TransQ WHERE "
  2. dateSource = dateSource & ((dateSQL))
  3. dateSource = dateSource & " GROUP BY ItemID ORDER BY Sum(TransQty)DESC"
  4.  
  5. Me.listDetailsBox.RowSource = dateSource
In case, you are wondering what is dateSQL
Expand|Select|Wrap|Line Numbers
  1. dateSQL = "TransDate>=" & Format(txtSalesStartDate, conJetDate) & " And TransDate<=" & Format(txtSalesEndDate, conJetDate) & ""
  2. datesSQL = dateSQL
Any other recommendation is welcome. Thanks again
Aug 29 '09 #3
NeoPa
32,556 Expert Mod 16PB
Check out the TOP predicate in the Help system for the SQL SELECT clause.

Finding Jet SQL Help may help.
Aug 29 '09 #4

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

Similar topics

3
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of...
0
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
0
by: Grzegorz Kaczor | last post by:
Hello, I have an ASP.NET application in my website in virtual folder A. This folder contains the application itself. I also have a data virtual directory B which contains data that can be seen...
6
by: Rob Williamson | last post by:
Does anyone know whether there is a way to create folders inside the right payne when you click on Tables or Queries or Forms or Reports in the the Objects side. I have alot of queries and forms...
18
by: Jerry Boone | last post by:
I'm looking for a way to fire a public sub/function when a form is opened and closed - without using form level events. I have already done some extensive form work with instancing, looping...
3
by: Marina | last post by:
Ok here's my problem.... I have a custom dialog box that allows the user to enter information to run a Parameter Query. This works GREAT, but I need that query to show as a form, not just the...
2
by: MyEmailList | last post by:
We have an Access data base with severl tables, queries and forms. We want to put it on the web. Is there a tool that will convert the Access queries and forms to ASP? Sorta like "splitting"...
0
by: mike0870 | last post by:
Hi, I've been at this one for hours and cannot not find any posts of anyone having the same problem. Ther scenario is, I need to fill a drop down box with a value in the grid row to pass to the...
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: 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...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.