|
MajP (TechnicalUser) |
7 Dec 08 23:57 |
Your example shows numeric values not alpha numeric values. If they are numeric values saved as text the solution is pretty easy. If they are alpha numeric values, there is no generic algorithm that anyone can write. Because you would have to sequence the values based on your buisness rules. For example Ab123xy What is the next value in the sequence? Ab123xz or Ab124xy or ac123xy or bb123xy or something else Depends on your rules. This will really complicate the problem. It is doable, but will be very complicated. If I had numeric values that had a natural sequence. I would build a function that returns the sequence as an array. This gives you the flexible to print the array, or save it to a table. here is my data of items tested CODEID final_sn 1 94353 2 94351 3 94351 4 94353 5 94357 6 94357 7 94369 8 94366 9 94367 10 94363 11 94369 12 94370 13 94371 14 94370 15 94372 I sort them and select unique values in "qrySNList" CODEfinal_sn 94351 94353 94357 94363 94366 94367 94369 94370 94371 94372 then build a function where I can pass in the min and max range. These values can come from a form's fields. I also pass in the name of the table/query and the field name. CODEPublic Function getMissingSN(strDomain As String, strFld As String, minVal As Variant, maxVal As Variant) As Long() Dim rs As DAO.Recordset Dim missingVal As Long Dim aMissingVals() As Long Dim intcounter As Integer Set rs = CurrentDb.OpenRecordset(strDomain, dbOpenDynaset) ReDim aMissingVals((maxVal - minVal) + 1) For missingVal = minVal To maxVal rs.FindFirst strFld & " = '" & missingVal & " '" If rs.NoMatch Then aMissingVals(intcounter) = missingVal intcounter = intcounter + 1 End If Next missingVal If aMissingVals(intcounter) = 0 Then intcounter = intcounter - 1 End If ReDim Preserve aMissingVals(intcounter)
getMissingSN = aMissingVals End Function I test this function CODEPublic Sub testMissing() Dim vals() As Long Dim intcounter As Integer vals = getMissingSN("qrySNList", "final_sn", "94354", "94370") For intcounter = LBound(vals) To UBound(vals) Debug.Print vals(intcounter) Next intcounter
End Sub You could save these values to a table. The result is CODE 94354 94355 94356 94358 94359 94360 94361 94362 94364 94365 94368 Changing this into the "beginValue - endValue" format will be a pain. It is doable, but will take some work. You have to read through the array checking to see if the value is more than one greater than the previous value. If it is you can concatenate it as the "endValue". If not you have to check the next value. Until you find a value more than 1 greater than the previous or you reach the end of the array. If you find an end value then the next value is you "beginValue". |
|