From: The Chomp on
Good Morning;

I am a little new at this so I hope I am asking the right question in the
right group

I am trying to set the primary key for a small database. As I understand it,
I do not want to use “auto number” for this field. What I was thinking was
trying something like.

What I am hoping to do is when a user opens a new record (using a form) the
primary key is auto generated.

Field_name = field_name=1. Would someone know how this is supposed to be
coded? The other question, would I need to set the first record as a dummy
record to put the first number in as it would be blank to start out.

Thanks All

Chomp

From: Marshall Barton on
The Chomp wrote:
>I am trying to set the primary key for a small database. As I understand it,
>I do not want to use �auto number� for this field.

Auto number is fine as long as you do not display it to
users.

>
>What I am hoping to do is when a user opens a new record (using a form) the
>primary key is auto generated.
>
> Field_name = field_name=1. Would someone know how this is supposed to be
>coded? The other question, would I need to set the first record as a dummy
>record to put the first number in as it would be blank to start out.


Use the form's BeforeUpdate event:
Me.pkfield = Nz(DMax("pkfield", "table"), 0) + 1
That will deal an empty table too so no need for a dummy
record.

NOTE: The pkfield will not be displayed on the screen until
after the record is saved.

--
Marsh
MVP [MS Access]