Adding a record number field

G

Guest

Good Day;

I would like to add record number field to a table. I figure all I have to
do is get the number of the last record and add "1" to it. Small problem, not
sure what the code would be to do this.
Thanks for any help

Chomp
 
S

Stefan Hoffmann

hi,

The said:
I would like to add record number field to a table. I figure all I have to
do is get the number of the last record and add "1" to it. Small problem, not
sure what the code would be to do this.
You can create a number on the fly:

SELECT (
SELECT Count(*)
FROM Table i
WHERE i.CK < o.CK
) AS RecNo, *
FROM Table o
ORDER BY o.CK

CK is a candiate key field, which identifies a record. It can be the
primary key. But the ORDER BY fields must be the same.

When you really like to store such a number, then use the Form_Update event:

If Me.NewRecord Then
Me![RecNo] = Nz(DMax("RecNo", "Table"), 0) + 1
End If

mfG
--> stefan <--
 
G

Guest

A faster way is

lngNewRecNo = Nz(DMax("[RecNo]", "TableName"), 0) + 1

Stefan Hoffmann said:
hi,

The said:
I would like to add record number field to a table. I figure all I have to
do is get the number of the last record and add "1" to it. Small problem, not
sure what the code would be to do this.
You can create a number on the fly:

SELECT (
SELECT Count(*)
FROM Table i
WHERE i.CK < o.CK
) AS RecNo, *
FROM Table o
ORDER BY o.CK

CK is a candiate key field, which identifies a record. It can be the
primary key. But the ORDER BY fields must be the same.

When you really like to store such a number, then use the Form_Update event:

If Me.NewRecord Then
Me![RecNo] = Nz(DMax("RecNo", "Table"), 0) + 1
End If

mfG
--> stefan <--
 

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