[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Access 2007 VBA - Change values of listbox items

Posted on 2011-02-28
3
Medium Priority
?
2,224 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

650 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