On Thu, 8 Jan 2009 09:46:43 -0800, Eric Johnson <Eric
I need to increment a key value by "1" with each new record and the "1"
needs
to be a text field so that the format of it can be "L0001", "L0002",.....
Using Access 2003.
If the L is constant and never varies, I'd suggest not storing it in the
field
at all. You can instead use an Integer or Long Integer number field with a
Format property of
"\L0000"
to just display the letter and the leading zeroes.
You can increment the ID in various ways. If this is a single user
database
then the simplest would be to use a form for data entry, and in its
Beforeinsert event put code like
Private Sub Form_BeforeInsert(Cancel as Integer)
Dim iNext As Integer
iNext = NZ(DMax("[ID]", "[tablename]")) + 1
If iNext >= 10000 Then
Cancel = True
MsgBox "All ID's have been used, shut off the PC and go home", vbOKOnly
Else
Me![ID] = iNext
End If
End Sub
For multiuser databases you need to take precautions against having two
users
create new records at the same time - post back with details if you need
this.