I was generating some numbers for a new database. Its based on some
entries the people do and it worked fine except for deleted records.
Private Sub generate()
Dim rst As Recordset
Dim maxof As Integer
Set rst = Me.RecordsetClone
If Not IsNull(Me.Level) And Not IsNull(Me.Control) Then
maxof = 0
If rst.RecordCount 0 Then
rst.MoveFirst
Do Until rst.EOF
If maxof < rst!GenNUMBER And rst!Level = Me.Level Then
maxof = rst!GenNUMBER
End If
rst.MoveNext
Loop
Me.GenNUMBER = maxof + 1
End If
If maxof = 0 Then Me.GenNUMBER = 1
Me.StudyID = "1" & [Level] & [Control] & Format(Me.GenNUMBER, "000")
rst.Close
End If
End Sub
this will go in find the MAX gennumber and just add 1.
but it you have 4 5 7 it will NOT go in and put in the 6 .
I said look you don't want that what if that number some how has to be
added BACK IN later, you assigned that number to a record then deleted
the record..
but they insist to fill in the list,, ok
I thought about in the loop adding something like
if isnull(rst!gennumber) then temp = maxof +1
and then using temp as the generate number but I am worried about one
thing...HOW can I test this to make sure in all instances?
does this sound like a good way to find missing numbers and generating
fillers into the missing ones (IF they exist)
yes the big problem in my mind is there are 3 different levels
1011 1012 1013
2011 2012 2013
3011 3012 3013
so I can't expect to end the loop on any certain value..