Edit a given value in a listbox

Access9001

Registered User.
Local time
Yesterday, 16:13
Joined
Feb 18, 2010
Messages
268
I have values in a listbox, say:

a
b
c
d


I want to basically be able to say "make item x = 'something'":

a
b
something
d

I've tried modifying it through List1.Column(0,x) but it says "object required." How can I do this?
 
Is your listbox bound? Is the value you're trying to update a primary key? How many columns does your listbox have?
 
I have been populating the listbox on the fly with vba using the additem command (I am listing files from a directory, but I want to be able to select a filepath and edit the path to allow for a certain form of date templating, but that's irrelevant to this question).
 
Is there a way to perhaps, instead, do this:

Remove 'c'
AddItem 'Something'
Move item to where c was?
 
A little demo of what you are doing may help
 
If you're going to have duplicate values in this listbox then you would need to be careful how text is replaced. Are you going to have duplicate records before or after replace?
 
If you are only editing the listbox values on the fly, as you say, then any changes won't be saved unless you can force a form save. This may not be possible due to the status of the app.

Is the rowsource coming from a value list?
 
It's coming from another function that lists files in a directory.
 
You should be looking to rename the file instead and call the function again?

If you still want to know how to replace items, here is a way:
Code:
    Listbox1.AddItem "-REPLACED-", Listbox1.ListIndex
    Listbox1.RemoveItem Listbox1.ListIndex
 
OP

I dont think you really want to do this at all - or you want to think carefully about it. A listbox should represent legal choices from which to make a selection.

Generally you will have a separate mtce function to manage those items.

If the list is say, salesmen and one has left, it may be better to flag the salesman as left, in some way, and for your list box to only select from the salesman who are still employed - and not to just delete a salesman.
 

Users who are viewing this thread

Back
Top Bottom