From what you have described, it sounds like the OSHA number should be generated as and when needed instead of being assigned and stored when the table row is created. My suggestion would be to just have the primary key (accident_id
) be an autoincremented long integer, the standard practice in Access. And also you need an accident_date
column to be a datetime
or similar. Or at the very least an accident_year
column. Then when you need an OSHA number (say in a report), just have some VBA to generate it using the primary key--accident_id
--and the accident_date
or accident_year
column. You will be taking advantage of the fact that Access autoincremented primary keys are never re-used--even when their rows are deleted, those numbers are never recycled to be used in other rows. So given a long integer primary key, and a date, you can always reproduce the exact same OSHA number, with a simple algorithm something like the following:
function osha_number(accident_id as long) as string
accident_year = ... ' get (last two digits of) accident year from accidents table using ID
year_first_accident_id = ... ' get ID of first accident of this year
year_this_accident_num = accident_id - year_first_accident_id + 1
osha_number = year_this_accident_num & "-" & accident_year
end function