What is the code to add records from a recordset to a listview control?
Printable View
What is the code to add records from a recordset to a listview control?
Code:
rs.MoveFirst
Do While Not rs.EOF
'Replace the following line with the correct data
ListView1.ListItems.Add , Key, Text, Icon, SmallIcon
rs.MoveNext
Loop
lvWebSites is my ListView control. FieldName is a form level variable dimensioned As Field. type and webaddress are fields in my Access database.VB Code:
SQL = "SELECT name, type, webaddress FROM websites " Set WebRs = WebDb.OpenRecordset(SQL, dbOpenDynaset) 'by setting a reference to the field name, VB does not have 'to iterate through the fields collection each time it goes 'through the loop Set FieldName = WebRs.Fields("name") Do While Not WebRs.EOF Set MyItem = lvWebSites.ListItems.Add(, , FieldName.Value) MyItem.SubItems(1) = WebRs("type") MyItem.SubItems(2) = WebRs("webaddress") WebRs.MoveNext Loop