Public Function nextIdString(ByVal nisFieldName As String, ByVal nisTableName As String, ByVal nisPrefix As String, Optional ByVal nisNumberOfZeros As Integer = 4) As Variant
nextIdString = Nz(DMax("[" & nisFieldName & "]", nisTableName, "[" & nisFieldName & "] Like '" & nisPrefix & "*'"), nisPrefix & "0")
' nisPrefix & "0" gives you a default value if one is not found in the table
nextIdString = Val(Mid(nextIdString, Len(nisPrefix) + 1)) + 1
' Get next numerical value by looking at the highest value number after the prefix and adding 1
nextIdString = nisPrefix & Format(nextIdString, String(nisNumberOfZeros, "0")) ' create next string Id
' Create new ID string by concatenating the formated number to the prefix
End Function