Public Function NewProjectnum() As Long
Dim lonCurrentYear As Long
Dim lonLastnum As Long
Dim lonTestYear As Long
Dim intCaseSelected As Integer
intCaseSelected = 1
lonCurrentYear = Year(Date)
lonLastnum = DMax("Projectnum", "ConsistencyMain")
lonTestYear = Val(Left(lonLastnum, 4))
If Val(Right(lonLastnum, 4)) >= 997 Then intCaseSelected = 2 'Rem Test for too many project numbers
Select Case intCaseSelected
Case 1 'Results OK
If lonTestYear = lonCurrentYear Then NewProjectnum = lonLastnum + 1 'Rem increment the project number for current year
If lonTestYear <> lonCurrentYear Then NewProjectnum = Val(Str(lonCurrentYear) + "0001") 'Rem increment the project number for the start of a new year
Case 2 'Too many projects
NewProjectnum = 9999
End Select
End Function