Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox AddItem - Index too large? 1

Status
Not open for further replies.
Dec 13, 2002
109
GB
Hello
I have a Listbox (Access 2003) and loop through to add items using
n = n + 1

It errors when n = 2 saying "Cannot addd item, Index is too large".

I can't see any obvious problem with it other than it doesnt want to add more than 1 item.

Ronald
 
Do you clear the listbox 1st before adding items?

What other properties are set om the listbox?

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Just the below code, no other properties really other than 5 columns:

If rs.RecordCount > 0 Then
With rs
Do While Not .EOF
n = n + 1
Myfunction.AddItem rs.Fields(0) & ";" & rs.Fields(1) & ";" & rs.Fields(2) & ";" & rs.Fields(3) & ";" & rs.Fields(4), n
.MoveNext
Loop
End With
End If


I think the form is corrupt somehow rather than anything progmatically wrong
 
What about this ?
Code:
With rs
  Do While Not .EOF
    Myfunction.AddItem .Fields(0) & ";" & .Fields(1) & ";" & .Fields(2) & ";" & .Fields(3) & ";" & .Fields(4)
    .MoveNext
  Loop
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes thankyou PHV
My "n" counter must have been debug I left in years ago.
For some reason it is in another form and works ok.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top