Link to home
Start Free TrialLog in
Avatar of JosephEricDavis
JosephEricDavis

asked on

Access 2007 VBA - Change values of listbox items

I have a listbox that is populated with multiple items, each having several columns worth of data.  I create the listbox items originally through code as is shown below.

Later, based on user actions I would like to be able to change some of the values of the different listbox items.

I've tried using code like this...
selectedIndex = lstbxAttachments.ItemsSelected.item(0)
lstbxAttachments.Column(1, selectedIndex) = "Removed"
lstbxAttachments.Column(3, selectedIndex) = ""
lstbxAttachments.Column(5, selectedIndex) = -1

But I end up throwing an exception when I try to change them like this.  Is there a better way to do this?
Set rs = DataService.Contract_GetContractAttachmentsByContractID(editID)
While Not rs.EOF
    strItem = CStr(rs("DocID")) + ";" + rs("DocDesc") + ";" + rs("Path") + ";" + rs("DocType") + ";" + CStr(rs("DocTypeID")) + ";1"
    lstbxAttachments.AddItem (strItem)
    rs.MoveNext
Wend
rs.Close

Open in new window

Avatar of conagraman
conagraman
Flag of United States of America image

this will loop throught a listbox and remove an item if it ='s  "hello world"

Dim i As Integer
For i = Listbox.ListCount - 1 To 0 Step -1
If Listbox.ItemData(i) = "hello world" Then
Listbox.RemoveItem i
Next i
Avatar of JosephEricDavis
JosephEricDavis

ASKER

I don't want to remove the item, I want to change the item.  So the same item will look different to the user.
ASKER CERTIFIED SOLUTION
Avatar of conagraman
conagraman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial