Mike,
I am an amateur, so this may or may not be the best way, but I was
intrigued by your question and here is what I came up with:
I would create a table to store the next approval number. The table
would have 2 fields: a sequence number and the year.
TableApprovalNumber
Field Name: Sequence Data Type: Number
Field Name: Year Data Type: Number
The table would always have only one record which will have the next
approval number to be assigned to an approved request.
On a form for entering/updating requests, I would have a command
button or checkbox called "Approved".
Cllicking on "Approved" would first compare the current year with the
year in TableApprovalNumber. If the current year is greater, then
TableApprovalNumber.Year is set to current year and Sequence is reset
to 1.
Then I concatenate the Sequence and Year to form the Approval Number.
Lastly, the Sequence is incremented so is ready for the next request
approval. Here is my code:
Private Sub Approved_AfterUpdate()
If Approved Then
Dim y As Integer 'year
Dim s As Integer 'sequence
Dim thisyear As Integer
y = DFirst("[Year]", "TableApprovalNumber")
thisyear = Format(Date, "yyyy")
'If this is the first number of a new year, reset the sequence to 1
If thisyear > y Then
DoCmd.SetWarnings (False)
DoCmd.RunSQL ("UPDATE TableApprovalNumber SET
TableApprovalNumber.Sequence = 1, TableApprovalNumber.[Year] = " &
thisyear & ";")
DoCmd.SetWarnings (True)
y = thisyear
End If
'Get approval number for this project
s = DFirst("[Sequence]", "TableApprovalNumber")
'Concatenate Sequence & Year to form Aproval Number
ApprovalNumber = Str(s) & "." & Str(y)
'Increment the sequence number in TableApprovalNumber
DoCmd.SetWarnings (False)
DoCmd.RunSQL ("UPDATE TableApprovalNumber SET
TableApprovalNumber.Sequence = [Sequence]+1;")
DoCmd.SetWarnings (True)
End If 'If approved
End Sub