Auto generating primary key number

T

The Chomp

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
 
M

Marshall Barton

The said:
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.
 

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