Cody Code


Hallo

I Just Have One Question in Regards to the Listview Control in VBA. I am trying to fill each column in my listview with data that is from a recordset.

i.e
rem lstviewItems in the listview control on the form

Set list = Me.lstviewItems.Object
With list
.ListItems.Add , , rec("Desc")
.ListItems.Add.SubItems(1) = rec("RetailCost")
.ListItems.Add.SubItems(2) = txtQty.Value

End With

The recordset works and everything but the only issue is that when the subitems are being added to the listview each subitem goes into a new row.

i.e

Description Price Qty
Shoe
19.99
3

Weird




Re: ListView in VBA

Andy Pope


Hi,

You keep on using Add in each line. You need to reference the newly added item row.
I have not tested this but something like the following. It maybe the ListItems is not zero based in which case remove the -1.

With list
.ListItems.Add , , rec("Desc")
.ListItems(.Listitems.count-1).SubItems(1) = rec("RetailCost")
.ListItems(.Listitems.count-1).SubItems(2) = txtQty.Value

End With







Re: ListView in VBA

Cody Code

Cool Thank You