Log in

View Full Version : LListBox Iteration and Sql Update Query



technocraze
12-14-2006, 08:07 AM
MAy I knw hw to iterate through the listbox and select the values. I am using something like this. Iam nt too sure as hw to use RecordSet and its properties. I am using MS Acess in vb environment

Dim item As Variant
Dim sqlStat as String
Dim studentId As string

Assign studenId to ListBox

foreach item in Listbox1.Selected
sqlStat = Update [TableName] set [field1, field2, field3] values [TextBoxes control] where studentId = Listbox1 control (selected value of listbox)

Cosmos75
12-14-2006, 08:53 AM
'Iterate through all rows in a listbox
Dim i As Long, iCount As Long

'Get count of total items in listbox
iCount = Me.Listbox1.ListCount

'Iterate through every row in the listbox
For i = 0 To (iCount - 1)
Debug.Print Me.Listbox1.ItemData(i)
Next i

'***********************************************

'If you are using a multi-select list box
'and only want those items that are selected
For Each Item In Me.Listbox1.ItemsSelected
Debug.Print Me.Listbox1.ItemData(Item) & " is selected"
Next ItemFYI, .ItemData returns the value of the bound column.