When I'm creating a table, I'd like to make the Primary Key an autonumber
that is the date and time the record is added ie. yymmddhhmmss
I don't want this number to change once it is entered automatically. Is
this possible?
Well, certainly not as an Autonumber. Autonumbers are either long
integers or GUIDs, not dates and not controllable.
I'd be very leery of using a date/time value as a PK. It would FORBID
you from ever using an Append query to add data to the table (since
you'll get more than one record added per second); if you have a
multiuser system, you'll also risk two users happening to insert
records at the same time. It also violates database design principles
to some extent, since you're using the one field for two different
purposes.
If you really want to do this anyway just set the field's data type to
Date/TIme, its DefaultValue property to =Now(), and its format to the
string you specified. It will actually store a Double Float number but
display it as you describe. Alternatively, define the field as being
of Text type (that's too big for a long integer) and use the Form's
BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me.txtTimeStamp = Format(Now(), "yymmddhhnnss")
Me.Dirty = False
End Sub
John W. Vinson[MVP]