Is It Possible To Generate An Auto-Incrementing Field?

  • Thread starter Thread starter mcl
  • Start date Start date
M

mcl

Is It Possible To Generate An Auto-Incrementing Field?

You know a field which just counts to the last record.

Field Name



1

2

3

4

to last record



Would it take some VBA to do?

If so, be very specific, I don't know VBA.
 
If your data already exists, you can use just create a new field in
your table and make it an autonumber field and it will do exactly as
you describe. It does *NOT* guarantee sequential values, only unique
ones. If you want strictly sequential values, you have to use DMAX.
There's information all over this NG about it. Search around.
 
well is it in a form or just a table or a report?

different ways for different situations;)
 
As this is the Queries newsgroup I'll assume you want to include
sequential field in a query. Provided the table has a primary key you
can do this with a subquery that counts all the records before the
current one. Here's an example that works on the Customers table in the
Northwind sample database (the primary key is CustomerID:

SELECT
(
SELECT COUNT(CustomerID)
FROM Customers AS B
WHERE B.CustomerID <= A.CustomerID
) AS Seq,
A.CustomerID,
A.CompanyName
FROM Customers AS A
ORDER BY A.CompanyName;
 
Back
Top