View Full Version : Loop through List Box


AccessKurzo
03-01-2001, 02:17 PM
How would you write the code to go through a List box, pull out all the indexes from selected rows(multi-select) and do an update query on each record?

KDg
03-02-2001, 01:03 AM
Hi Kurzo,

you need to do a for each - items selected. You may also need to do a check for a null value as there can be nothing selected in the box sometimes,

For Each vItem In Me.lstBooked.ItemsSelected
myKey = DateConvert(Me!lstBooked.ItemData(vItem))
if MsgBox("Are you sure you want to cancel the " & Me!lstBooked.ItemData(vItem) & "?", vbDefaultButton2 + vbYesNo)=vbYes then
Let strSQL = "UPDATE yada yada yada WHERE KeyField=" & myKey & ";"
dbs.Execute strSQL
End If
Next


HTH

Drew

AccessKurzo
03-02-2001, 06:13 AM
Thanks for your help Drew http://www.access-programmers.co.uk/ubb/smile.gif