473,504 Members | 13,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2007 Need to count ocourances of "Running" and incrementally number them.

5 New Member
In Access 2007, I have a query it has 2 collumns one is "Location" and the other is titled "Activity". Lets say "Location" has 2 choices "Here" or "There". While "Activity" has several that can be done at both locations. Lets say "Eat, Drink, Rest, Run, Walk" I want to count on the rows of data incrementally how many times I run, here and add incrementally in a third collumn how many times it is done. I can have this in a new query or the existing one.

So It would look like (table example):
Run Here
Run There
Walk Here
Run There
Run Here

And the results would be
Run Here 1
Run There 1
Walk Here 1
Run There 2
Run Here 2
May 21 '10 #1
8 1801
Jim Doherty
897 Recognized Expert Contributor
@union51
Welcome to Bytes :)

Assuming to have read you right this relies on a table called Table1 having two columns Location and Activity containing the data you describe. Paste this into the SQL window of an Access query and run it. It presents three columns one being concatanated (which you can delete if you wish. Remember you must have a table called table1 or alter the references in this SQL replacing Table1 with your own

Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.Location, Table1.Activity, [Location] & " " & [Activity] AS [Physical Activity], Count(Table1.Activity) AS Result
  2. FROM Table1
  3. GROUP BY Table1.Location, Table1.Activity, [Location] & " " & [Activity];
May 21 '10 #2
union51
5 New Member
@Jim Doherty
Thank you for the quick reply....
Is there a way to count each row incrementally?
So that I could have
here run 1
here run 2
there run 1
there walk 1
here run 3
May 21 '10 #3
Jim Doherty
897 Recognized Expert Contributor
@union51
oh I get you now a running sum....well just now I am going for a meal so unless someone else contributes this in the meantime.... I will come back to you in a bit
May 21 '10 #4
union51
5 New Member
@Jim Doherty
No problem, I had figured I could do it in a VBA loop then had no idea on how to count my instances.
Thank you for your help.
May 21 '10 #5
Jim Doherty
897 Recognized Expert Contributor
@union51
Hi again

You can play with a loop if you wish to hone your VBA skills but SQL can handle this too.
To make the running sum work add an extra field called 'id' to the table and set it to autonumber then let it fill the column with a sequence of numbers.

Now that we have a series of some numeric data available we can now obviously implement a running sum based on counting the 'id' column and significantly relate that to the location column and the activity column.

Given that we are dealing with the table called table1 as mentioned earlier. the following SQL statement will give you your running sum per location/activity as desired

Expand|Select|Wrap|Line Numbers
  1. SELECT LA.id, LA.Location, LA.Activity, LA.[Running Sum]
  2. FROM [SELECT LA.id, LA.Location, LA.Activity, (select count([id]) FROM table1 where id <=LA.id and location=LA.location and activity=LA.activity) AS [Running Sum]
  3. FROM Table1 AS LA]. AS LA
  4. ORDER BY LA.Location, LA.Activity, LA.[Running Sum];
May 21 '10 #6
union51
5 New Member
Sorry, I was out mowing my yard by popular demand.
I am getting a error on the bracket between from & select. Will try to figure it out however.
May 22 '10 #7
Jim Doherty
897 Recognized Expert Contributor
@union51
I don't know what happened there... fixed

Expand|Select|Wrap|Line Numbers
  1. SELECT LA.id, LA.Location, LA.Activity, LA.[Running Sum] 
  2. FROM (SELECT LA.id, LA.Location, LA.Activity, (select count([id]) FROM table1 where id <=LA.id and location=LA.location and activity=LA.activity) AS [Running Sum] 
  3. FROM Table1 AS LA) AS LA 
  4. ORDER BY LA.Location, LA.Activity, LA.[Running Sum];
May 22 '10 #8
union51
5 New Member
@Jim Doherty
Oh, well that is perfect thank you so much for the help!
May 22 '10 #9

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

Similar topics

73
3943
by: Sean Dolan | last post by:
typedef struct ntt { int type; union { int i; char* s; }; }nt; nt n; n.i = 0;
71
3085
by: Greg | last post by:
Is it your general opinion that C# is generally designed/intended/ready to replace C++? I know the answer is not black and white but please repond YES or NO (add any comments if you would like) ...
45
3350
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
11
1400
by: Dennis D. | last post by:
Hello: So far I am into XML, XHTML, JavaScript, VB.net, and the .Net Framework. I have the ability to use SQL server, MS Access, or XML as databases, and 1.1 and 2.0 are installed on the server....
9
2082
by: casper christensen | last post by:
Hi When someone fills the form on my site, and id is created in my database. (see below) http://www.affiliatesjunction.net/directory.php?ax=out&id=XXX after submitting the form they are...
1
1187
by: Fabrizio | last post by:
My web cam save a file each minute with a name like this "history20070611s202635195.jpg" Do you know a script in php that can animate the last 60 jpg ? What I like is something like this: ...
5
1283
by: Rick A.B. | last post by:
Article in SD Times http://www.sdtimes.com/download/images/sdtimes179.pdf Microsoft SQL Server is still No. 1. According to the 2007 Database and Data Access, Integration and Reporting...
6
4458
by: capricious | last post by:
Is it possible, so that when you do multiple <UL>'s to control how deep the UL's are marked? For example, it would defaultly look like this with multiple ULs and LIs: -- Code : Main...
8
5048
by: howa | last post by:
Just found a funny things.. in HTML4's dtd, http://www.w3.org/TR/html4/strict.dtd language is not valid, i.e. <!ELEMENT SCRIPT - - %Script; -- script statements --> <!ATTLIST...
24
8179
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
7213
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
7298
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,...
1
7017
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...
0
7471
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
5610
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,...
1
5026
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...
0
3187
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...
0
1526
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 ...
0
406
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...

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.