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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox problem 1

Status
Not open for further replies.

jmstarbuck

Programmer
Aug 11, 2003
90
US
I am trying to loop through a listbox to remove all the items before refilling it. I've never done this before and haven't found an example that has helped yet.

Anyway, I try to do it in the code below. The problem is that when I exit the for loop there are still items in the listbox. If I keep forcing it back through the for loop I will eventually delete all the items.

Please let me know if you can see what I am doing wrong..

Code:
 qualifylistcount = Nz(Forms!Application_Form.LBQualify.ListCount, 0)
If qualifylistcount > 0 Then
    For i = 0 To qualifylistcount - 1
      j = Forms!Application_Form.LBQualify.ListIndex
      Forms!Application_Form.LBQualify.RemoveItem i
    Next i
End If
qualifylistcount = Nz(Forms!Application_Form.LBQualify.ListCount, 0)
 
Replace this:
For i = 0 To qualifylistcount - 1
with this:
For i = qualifylistcount - 1 to 0 Step -1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV

Thank you so much. I have been banging my head on this for 3 hours. You have given me my life back!!

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top