?
Solved

Access 2007 VBA - Change values of listbox items

Posted on 2011-02-28
3
Medium Priority
?
2,155 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:JosephEricDavis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:conagraman
ID: 34999709
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
0
 
LVL 7

Author Comment

by:JosephEricDavis
ID: 34999727
I don't want to remove the item, I want to change the item.  So the same item will look different to the user.
0
 
LVL 10

Accepted Solution

by:
conagraman earned 2000 total points
ID: 34999903
yes that is how you do it first you remove the item then you add it back in. there isnt a way to "change"  it per say.

Dim i As Integer
For i = Listbox.ListCount - 1 To 0 Step -1
If Listbox.ItemData(i) = "hello world" Then
Listbox.RemoveItem i  '<<remove it
Listbox.AddItem "yourstring, i   '<<add it back in
Next i

   
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question