Is It Possible To Generate An Auto-Incrementing Field?

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.
 
P

pietlinden

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.
 
N

Naeem

well is it in a form or just a table or a report?

different ways for different situations;)
 
J

John Nurick

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top