Solved

Access 2007 VBA - Change values of listbox items

Posted on 2011-02-28
3
2,107 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 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

726 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