Boundary Checking for ADODB.RecordSet Objects

Not that this is a very elegant solution, but I needed to get rid of a bug in production. The cause of this was the check for one of the recordset's fields. After looping a second time and MoveNext() bringing the recordset to EOF, you couldn't check its values anymore. So to fix this I added the following line:

If Not rsUinvcat.EOF Then

This checks your boundary conditions before attempting to read a value that might not currently exist. Always check your bounds!


For i = 0 To intCols
If Not rsUinvcat.EOF Then
If rsUinvcat![uinvcat] = i + 1 Then 'will error if EOF
astrInvHeader(i) = rsUinvcat![Description]
rsUinvcat.MoveNext
End If
End If
If Not rsuinvcatadmincost.EOF Then
If rsuinvcatadmincost![uinvcat] = i + 1 Then 'will error if EOF
astrInvHeader(i) = rsuinvcatadmincost![Description]
rsuinvcatadmincost.MoveNext
End If
End If
Next i

Forgive the lack of tabs, this new CMS ignores them.