The whole idea of using a collection is to ignore the duplicates, thus the on error resume next. There are also several more if ... then statements in the procedure so the on error goto 0 is to reset the error handler. Not sure its needed but it doesnt make a difference either way.
Originally I would loop through the recordset and would concatenate a string which may look like 1,1,2,3,4,5,1,3,2,4,6,3,3. I would then pass that string to a function which used a collection, setting a key to eliminate the duplicates.
Code:
If LvDist(strChk, rs!PartyID) < 4 Then
strOut = strOut & rs!PartyID & ","
End If
I then changed the code to
Code:
If LvDist(strChk, rs!PartyID) < 4 Then
On Error Resume Next
MyCol.Add rs!PartyID, CStr(rs!PartyID)
End if
The collection was being populated as MyCol.Count would show the correct number.
If I tried
Code:
For each varItem in MyCol
debug.print varItem
Next
or
For i = 1 to MyCol.count
debug.print MyCol(i)
Next i
the debug.print line would error "no current record" A few other error messages popped up but I dont remember them.
As soon as I assigned the recordset value to a variable it worked without issue. I'm just baffled why using a variable works and using rs!Somefield doesn't.