Automatically inserting number

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

In an ID field, I would like Access to populate numbers, 1
plus the previous recored's value. I can't use an
AutoNumber field, because this information is going to be
exported from the table and sometimes updated information
will be imported back into the table. I need to be able to
change the ID field if necessary to accomodate conflicts. I
just want each record to have an unique number to help with
lookups. How can I do this?

I don't want to do replication for various reasons.
 
DMax() gets the maximum existing value.

Use the form's BeforeUpdate event so it fires at the last possible moment
before the record is saved, to reduce the chance that 2 users get the same
number at the same time.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.ID = Nz(DMax("ID", "MyTable"), 0) + 1
End Sub
 
I tried this and I keep getting 0 as the answer. I can't
figure out what I'm doing wrong. Does anyone have an idea
or anyway to automatically generate an unique number. I
don't care that the number is exactly 1 more than the
previous number.
 
Does anyone have an idea
or anyway to automatically generate an unique number. I
don't care that the number is exactly 1 more than the
previous number.

Use an AutoNumber field.
 
Back
Top