?
Solved

Add Sequential Number to Query Records

Posted on 2004-04-24
4
Medium Priority
?
738 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

764 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