Weird collection processing results - needs an expert

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone fathom why this code fails? I'm totally stumped

Global glbcolSA As New Collectio
Global glbcolSADesc As New Collectio
Global glbcolSATel As New Collection
......
Do While Not rs.EO
MsgBox rs("SupportArea") <------ Displays ite
glbcolSA.Add rs("SupportArea"
glbcolSADesc.Add rs("Description"
glbcolSATel.Add rs("CustSuppTel"
MsgBox glbcolSA.Item(glbcolSA.Count) <--- Displays ite
rs.MoveNex
Loo
MsgBox glbcolSA.Count <------- Displays
For x = 1 To glbcolSA.Coun
MsgBox glbcolSA.Item(x) <------ Fails
Next
 
Actually, user defined collections start at one!

The problem is that collections support storing of nulls...but

msgbox null

Is not legal. The code is fine..but the poster is storing nulls..which have
to be dealt with.

So,

MsgBox nz(glbcolSA.Item(x),"")

Should work just fine....

And..yes..just like you...I find the inconsistency from "zero" based
collections to 1 base collections always a source of confusion!
 
I'm going to throw out another option.
This line:
glbcolSA.Add rs("SupportArea")

I think it actually adds the Field object to the
collection, not necessarily the value. Try
glbcolSA.Add rs("SupportArea").Value

But, what error do you get when you say it fails? Error
94 "Invalid Use of Null" or Error 3021 "EITHER BOF or EOF
is true"

If its the first error, then Mr. Kallal's post would be
accurate. If it's the second, then add the .Value.


Chris
 
Back
Top