[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Add Sequential Number to Query Records

Posted on 2004-04-24
4
Medium Priority
?
747 Views
Last Modified: 2008-03-17
I have a Query that returns records based on whether or not a check box is check. The Query is also sorted "Ascending" by another field.
I want to created a column in the query that will sequentially number the records that are returned.

Help Please
omron60
0
Comment
Question by:omron60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 27

Expert Comment

by:jjafferr
ID: 10908111
Hi omron60,

make this ield in your query
NextNumber: DCount("[AnyFieldNameInQuery]","YourQueyName","[AnyFieldNameInQuery] <=" & [AnyFieldNameInQuery])

SAVE the query after putting the name in the field above, then run it.

Hope this helps

Jaffer
0
 
LVL 11

Accepted Solution

by:
Quetzal earned 500 total points
ID: 10908129
If you are retrieving records from a single table and sorting the results on a field that is unique to each record, here is a simple way to do what you want.  Add a column to your query as follows (this assumes that the table is called tblTable and the field you are sorting on is called SortField):

Sequence: DCount("SortField","tblTable","SortField <=" & [SortField])

If SortField is text data, modify as follows (surround [SortField] by single quote):

Sequence: DCount("SortField","tblTable","SortField <='" & [SortField] & "'")
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10908271
Check also this for a ranking in a query:
http://support.microsoft.com/support/kb/articles/Q208/9/46.ASP

Nic;o)
0
 

Expert Comment

by:eoinol
ID: 10918917
Use a static variable

Function IncrementalNumber(Optional strType As String) As Integer

Static NextNumber As Long
' Eoin O'Loughlin

If strType <> "Reset" Then
    NextNumber = NextNumber + 1
Else
    NextNumber = 0
End If
IncrementalNumber = NextNumber

End Function

In your query have a field that calls incrementalNumber() as MyNo
If you want to reset the number call IncrementalNumber("Reset") - this should be done before you run the query

0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question