Set Date as Primary Key?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a form needs to have a date as record number, or primary key, can't
be duplicated.

It should work this way. I click on New record button, a new record created
based on the date. For example, my last record is Nov. 19, 2004, the next
new record should be Nov. 20, 2004, the next new record should be Nov. 21,
2004,.....

Thanks in advance!
 
Huaqin said:
Hi,

I have a form needs to have a date as record number, or primary key, can't
be duplicated.

It should work this way. I click on New record button, a new record created
based on the date. For example, my last record is Nov. 19, 2004, the next
new record should be Nov. 20, 2004, the next new record should be Nov. 21,
2004,.....

Did you have a question?
 
You can use a Date/Time field as primary key. Provided you record dates only
(not date and time), this works very well.

Because times are floating point values, it can be difficult to locate the
record you want if there are times in the field, e.g. if you use =Now() as
the default value, when you intended =Date().

If you want your form to automatically supply the next date when you begin
entering a record, use the BeforeInsert event procedure of the form:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.MyDateField = Nz(DMax("MyDateField", "MyTable") + 1, Date())
End Sub
 
Back
Top