How to show the record number in a MS Access repor

2020-02-16 03:17发布

问题:

I'm using MS Access to make a small piece of software for an office. When we insert a record the record ID does not always follow the sequence of natural numbers, starting from 1. but in the first column I want a self-generated serial number(S.N).

SN  |   Discription |
----+---------------+
1   |   Computer    |
2   |   Mobile      |

I Want these S.N to always start from 1 and count all records in the report table Plsease help.

回答1:

I assume your table name is inventory:

SELECT DCOUNT("[Description]","[inventory]","[Description]<='" & [Description] & "'") AS rank, inventory.*
FROM inventory
ORDER BY [Description]

DCOUNT function counts the number of rows that satisfy the a given criteria. In this case we count the number of rows that are less than the current row. Things will work if the column you use has unique values.