Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

Row Number in a Query

Adding a Row Number in your Query.

In this tutorial you will learn how to add a ROW number to a Query.

Take an example Table of some Names.

tblNames
IDFirstName
1Fred
3Barry
4Joan
5Ben
7Will

You wish to add the Row number beside them:

tblNames
Row #IDFirstName
11Fred
23Barry
34Joan
45Ben
57Will

There is no row_number like in SQL Server.

You can achive this in a number of ways:

	RowNum: DCount("[ID]","[tblNames]","[ID]<=" & [ID])
	

See this FREE Tip on DCOUNT.

	SELECT A.*, 
		(SELECT COUNT(*) FROM tblNames WHERE A.ID>=ID) AS RowNum
	FROM tblNames AS A
	ORDER BY A.ID;
	

These are not very efficient so don't use them on large recordsets.

An addition to this could be adding the Ordinal or Suffix of st, nd, rd or th

Just create a Function:

	Function myOrdinal (D as Integer) as String
		Dim Suffix as String
		Select Case D
			Case 1, 21, 31: Suffix = "st"
			Case 2, 22: Suffix = "nd"
			Case 3, 23: Suffix = "rd"
			Case Else: Suffix = "th"
		End Select
		myOrdinal = D & Suffix
	End Function
	

First shown at Forum.

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

Check out these other pages that may be of interest to you:

5/26/2023Hide With Macro
5/25/2023Calculator 6
5/24/2023Object Size Analyzer
5/24/2023Calculator 5
5/23/2023Plural
5/22/2023Calculator 4
5/19/2023Calculator 3
5/18/2023Calculator 2
5/17/2023Calculator
5/16/2023Variable Default
 

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn
Copyright 2023 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/29/2023 2:31:44 AM.