473,399 Members | 4,192 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,399 software developers and data experts.

Increment number when the same value

2
Hi,

I'm trying to do below numbering in access:

apple 1
apple 2
apple 3
apple 4
orange 1
orange 2
plum 1
peach 1
peach 2
peach 3

Does anybody know how i can do that in query?
Mar 9 '11 #1
3 3467
TheSmileyCoder
2,322 Expert Mod 2GB
This code placed in a module can act as a simple cumulative counter:
Expand|Select|Wrap|Line Numbers
  1. Public Function cumCount(strText As String) As Long
  2.     'Cumulative counter for query
  3.     Static strOldText As String
  4.     Static lngCounter As Long
  5.     If strText = strOldText Then
  6.         lngCounter = lngCounter + 1
  7.     Else
  8.         lngCounter = 1
  9.         strOldText = strText
  10.     End If
  11.         cumCount = lngCounter
  12.  
  13. End Function
Your SQL would then look like so, for example:
Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_Fruit.Text, CumCount([Text]) AS [Counter]
  2. FROM tbl_Fruit
  3. ORDER BY tbl_Fruit.Text;
  4.  
Mar 9 '11 #2
Kuba S
2
That's exactly what i was looking for!!
Thanks very, very much!
Mar 9 '11 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Your welcome
TheSmileyCoder
Mar 9 '11 #4

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

Similar topics

13
by: William Payne | last post by:
Hello, I would like to know if EXIT_FAILURE/SUCCESS has the same value on all platforms? I am writing a few scripts (I know shell scripts are off-topic here) to test my C programs and they depend...
2
by: Ramez T. Mina | last post by:
I tried to increment variable when I click on a button, but it didn't work. I use the VB.NET editor and not the HTML editor. any one can help??
4
by: Rodger Dusatko | last post by:
In VB .NET I am having problems setting breaks. I want the break to be independant of any single function: for example: err.number or global variables When I try to set a break with the 'Data'...
8
by: Peter | last post by:
Hi, there I have created an stored procedure using the DDL below for my MS Access Database and no error occurs. Also it can create an stored procedure if I changed the parameter from "" to...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
6
by: Martin | last post by:
Hi all, I'd like to find a .NET Collection in which I will be able to set many keys for the same object. For example, I would like to do something like that : Dictionary<long,...
2
by: rahulhere | last post by:
send some example how we increment a global variable value som few functions
0
by: Amar | last post by:
Hi, I have a generic list with a some objects of a particular class in it. I have implemented a IComparer for the the class and pass it to the List. The list.sort method works fine when the value...
7
by: john_smith_1221 | last post by:
Hello, I need to use the rand() function to generate a random value, I already know how to do it with srand(time(NULL)) and its "randomness" is sufficient for me, the problem is my code requires to...
4
by: coderdon | last post by:
hi, i have two combo box with same values when i select some value in one combobox the other combo box should not allow to select the same value can any one help me with the javascript to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.