Hi,
Anybody can help me?
I need a table to generate autonumber with specific format of number but not
using access default increment autonumber, for example: 0311-0001 and next
no. 0311-0002 where 0301 mean year month and behind is running no.
Thk,
Pat
This is called an "Intelligent Key" - and unfortunately that's not a
compliment. Storing data, such as a date, in a field along with other
data is generally considered unwise; fields should be "atomic", i.e.
have only one indivisible value. This kind of key should ONLY be used
for compatibility with an existing manual system.
If you are going to use this key, I'd suggest using *two* fields - a
four byte text field for the month and year (I'll call it KeyYYMM) and
an Integer for the sequential portion (KeyN). You'll need to do all
your data entry using a Form - table datasheets don't have any usable
events. In the Form's BeforeInsert event you'll want code like this:
Private Sub Form_BeforeInsert(Cancel as Integer)
Dim strYYMM As String
strYYMM = Format(Date(), "yymm") ' generate 0311, frex
Me!txtKeyYYMM = strYYMM
Me!txtKeyN = 1 + NZ(DMax("KeyN", "yourtable", "[KeyYYMM] = '" & _
strYYMM & "'"))
End Sub
This will sometimes run into problems if two users are simultaneously
creating new records in a shared database; more elaborate schemes can
be devised to avoid such problems.