The basic logic to generate the next, sequential, TaskID Number, minus the missing critical piece of information listed previously in Post #3 would be something similar to:
NOTE: This code requires a strick adherence to the TaskID Format of: YYYY-JJ-TT and a seeding of the 1st ID, meaning that you need only a single, manually entered ID, for the code to work.
Code:
Expand|Select|Wrap|Line Numbers
Public Function fGenerateNextTaskID() As String
'Task ID Format: YYYY-JJ-TT (Year - Job# - Task#)
Dim strLastTaskID As String
Dim intLastTaskIDYear As Integer
Dim intLastTaskIDJobNum As Integer
Dim intLastTaskIDTaskNum As Integer
Dim intNextTaskIDYear As Integer
Dim intNextTaskIDJobNum As Integer
Dim intNextTaskIDTaskNum As Integer
strLastTaskID = DLast("[TaskID]", "tblTasks")
intLastTaskIDYear = Val(Left$(strLastTaskID, 4))
intLastTaskIDJobNum = Val(Mid$(strLastTaskID, 6, 2))
intLastTaskIDTaskNum = Val(Right$(strLastTaskID, 2))
If Val(intLastTaskIDYear) = Year(Date) Then 'Not a New Year
intNextTaskIDYear = intLastTaskIDYear
Else
intNextTaskIDYear = intLastTaskIDYear + 1 'New Year, increment by 1
End If
'Missing information concerning Job Number
'If Job Number is the same
intNextTaskIDJobNum = intLastTaskIDJobNum 'maintain Current Job#
intNextTaskIDTaskNum = intLastTaskIDTaskNum + 1 'increment Task#
'Else
intNextTaskIDJobNum = intLastTaskIDJobNum + 1 'increment Current Job#
intNextTaskIDTaskNum = 1 'Reset Task# to 1
'End If
fGenerateNextTaskID = CStr(intNextTaskIDYear) + "-" & Format$(intNextTaskIDJobNum, "00") & _
"-" & Format$(intNextTaskIDTaskNum, "00")
End Function
Comment