sam said:
Yes, Autonumber. I've thought about this method but it
will be multiuser and so I can't do it that way. Any
other ideas?
To generate a number series in a multi-user environment, here's a
solution I use all the time.
You will need a new separate Table (tblSeries) having just one Field
(NextNumber) of type Long Integer to store the incrementing number.
The Table will have no index and will not be related to any other Table.
Dim rst As Recordset, db As Database
Dim lngNextNumber As Long
Set db = CurrentDb
'Open tblSeries, lock, read next number, increment, update and unlock.
Set rst = db.OpenRecordset("tblSeries", , dbDenyRead)
With rst
.MoveFirst
.Edit
lngNextNumber = ![NextNumber]
![NextNumber] = lngNextNumber + 1
.Update
End With
rst.Close
Set db = Nothing
This code is designed for Access 97. If you are using a later version,
you will need to use DAO.Recordset and DAO.Database and make sure you
have the appropriate reference set for the DAO Library.
The incrementing number is returned to you in the variable
lngNextNumber.
This code should be in the Click event of the command button you use
finally to commit your numbered record. This must happen after all
opportunities to abort your record, otherwise you could have gaps in
your numbering to explain to your auditors! After this code, you will
need to store the number value in your Table holding your records.
If, in your system, you need other unrelated number series, just add
another Field to tblSeries and manage it in a similar manner.
hth
Hugh