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

Cycle through listbox 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
If I can do this in one part of my program:

TYN=7
Me.List7.Listindex = TYN

Then why can't I do this

For TT=0 To Me.List7.Listcount-1
Me.List7.Listindex=TT
Next

Thanks

 
List7 must have the focus if you want to change its ListIndex property.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks pwise, TYN was an integer. Thanks PHV, setting focus was the answer. Have a star and thanks again.
 
Why is this not happy. The list has a column heading, I have tried all permutations of TT starting with 1, and Listcount - 1, -2 etc.

Dim TT As Integer
Me.List5.SetFocus

For TT = 0 To Me.List5.ListCount - 1
Me.List5.ListIndex = TT
Me.Shot = Me.S3.Caption
Next

Me.List5.Requery
 
The heading of a listbox is Row zero, so you need to start TT at one.
 
Thanks Remou, I removed the column headings so I could get back to zero. However I cannot seem to get this code to work.

Private Sub CVRT_Click()
Dim TT As Integer
Me.List5.SetFocus

For TT = 0 To Me.List5.ListCount - 1
Me.List5.ListIndex = TT
Set RS = Forms.ShotData.RecordsetClone
RS.FindFirst "[ID2] = " & Me.List5.Column(1)
Me.Bookmark = RS.Bookmark
Me.Shot = Me.S3.Caption
Next

End Sub


I am cycling through a listbox, which changes the record of the bound form, and at each step of the cycle puts the value of a caption into a bound field "Shot" However it persists in going through the list and ends leaving the last record unmodified. Occasionaly it throws up a dialogue saying I had not used the Edit, Update functions and the record cannot be saved. Don't know why something simple in logic is driving me nuts. Thanks
 
Why are you going through the form rather than the recordset?

Code:
Private Sub CVRT_Click()
Dim TT As Integer
Me.List5.SetFocus

For TT = 0 To Me.List5.ListCount - 1
Me.List5.ListIndex = TT
Set RS = Forms.ShotData.RecordsetClone
RS.FindFirst "[ID2] = " & Me.List5.Column(1)
'Me.Bookmark = RS.Bookmark
'Me.Shot = Me.S3.Caption
rs.Edit
rs.Shot = Me.S3.Caption
rs.Update
Next
Me.Requery
End Sub
 
Oops.
rs[red]![/red]Shot = Me.S3.Caption
 
Thats okay, it did work okay with rs.shot!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top