Generating an Unique Number

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

Chris

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.
-----Original Message-----
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

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
..
 
Sorry wrong answer

Chris said:
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.
.
 
Back
Top