Modifying listbox values (1 Viewer)

Spooky

Registered User.
Local time
Yesterday, 21:43
Joined
Jun 11, 2012
Messages
18
[brief]
Userform / vba / word
I have a listbox in a userform that I wish to modify one item.

Basically the list contains data relating to an individual. There are 30 items per record.
There can be one to many individuals listed in a multicolumn list box.

How can I change one item - eg listbox(x,27) to a new value after its been created?

eg, I want to do it automatically behind the scenes based on other input
 
Last edited:

Cronk

Registered User.
Local time
Today, 15:43
Joined
Jul 4, 2013
Messages
2,770
The list box column property is read only ie lstYourListBox.column(1,27) gives you the value of the second column (it's zero based) on the 27th row.

To change it's value, you need to change the row source of the list box.
 

Spooky

Registered User.
Local time
Yesterday, 21:43
Joined
Jun 11, 2012
Messages
18
The list box column property is read only ie lstYourListBox.column(1,27) gives you the value of the second column (it's zero based) on the 27th row.

To change it's value, you need to change the row source of the list box.

Sorry, Im not that flash with the terminology.
So, I would need to rebuild the listbox from the source and cant change individual items (as they are read only?) within that record with .removeitem(x) and then .additem(x)?

Code:
            UF1.Listbox.RemoveItem (27)
            UF1.Listbox.AddItem "New Value", 27
 

Cronk

Registered User.
Local time
Today, 15:43
Joined
Jul 4, 2013
Messages
2,770
You can use Add/RemoveItem methods from Access 2013

My valued listed list boxes are normally static. Otherwise they are normally based on tables/queries/sql so I don't use the methods.

Using AddItem in a multicolumn listbox, you'd have to add the values of all the columns in the row eg

UF1.Listbox.AddItem ("Column1Value;Column2Value;.....", 27)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:43
Joined
Feb 28, 2001
Messages
27,001
It is probably not such a good idea to try to alter the contents of a list box since your changes would almost certainly be lost after executing a .Requery or after a Form_Current event (that implies a .Refresh). Your changes would be subject to being overwritten since the list box and combobox are usually guided by a .Rowsource property.

The one exception is if you have a VERY short list of possible values, it MIGHT be possible to enumerate the values in the .Rowsource property, which would give you a comma-separated list of values. If this list of possible values gets too long, rewriting the list becomes impractical.
 

Users who are viewing this thread

Top Bottom