Double click Listbox to edit item

  • I have a list box that is populated on initialization. The user then can add or delete items from this listbox.

    I want the user to be able to EDIT the items as well the listbox has 4 columns.

    here is the double click code:

    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
     'ListBox1.List (ListBox1.ListIndex) this returns the item in the listindex where double clik has happened.'
    End Sub

    the double clik opens up a form with two textbox for input and an ADD button that is suposed to add the tex to the listbox in UserForm 1.

    How do I do this? I have no Class function created and everything is local

  • Re: Double click Listbox to edit item

    (Code added 'freehand' and unchecked. It might error, but the general principal still applies...)

  • Re: Double click Listbox to edit item

    ok that gives me an idea of how to work it out.

    Listbox1 in userform1 is loaded before hand
    UserForm2 has two textboxes where the user inputs info and a button to ADD the info to the listbox, all this in user form 2.

    so when I hit the button ADD

    something like

    should happen however indexlst is empty and I fill it like this

    Public indexlst As Integer
    Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
     indexlst = ListBox1.ListIndex
    End Sub
  • Re: Double click Listbox to edit item

    Not too sure I understand correctly. However, double clicking the ListBox opens a second form for the user to input text to go in the first and third columns of the selected list item... If that's correct, then

    On The userform, include 2 buttons, "OK' and 'Cancel' (For example). Code as Follows:

  • Re: Double click Listbox to edit item

    yep does the trick however isnt a textbox its a DTpicker so if I try and change the date it does not work. heres the code

    i think it has to do something about that .value at the end of fechaentregaadd

  • Re: Double click Listbox to edit item

    ok solved it here it is however when I fill before hand say ListBox1.List(ListBox1.ListIndex, 3) and I run the code UserForm2.txtpersonaadd.Text will always put "" in column 3. If there is something in column 3 and only modify what is in column 1 how would I go through with it??

  • Re: Double click Listbox to edit item

    Can't comment - the .Value property contains the date in a DTPicker control, so your code looks right from here...

    The actual error might help, but I'm guessing it'll be 1004.

  • Re: Double click Listbox to edit item

  • Re: Double click Listbox to edit item

    its been modified:

    so for example if the user double clicks the item he will input info, that will be input by the CODE into UserForm2.fechaentregaadd.Value and UserForm2.txtpersonaadd.Text: the list will have new info.

    if the user decides he mistyped what the code inputs to


    and double clicks again on the item , the


    will erase the info here

  • Re: Double click Listbox to edit item

    Have a new prob on this issue. I have the addDoc form to appear as soon as someone double clicks on the listbox item. Lets say he does it once, on item 1, and places info in only 2 columns say (column 3) ListBox1.List(ListIndex, 4) and (column 0)ListBox1.List(ListIndex, 1) clicks (add) command_button_1 on the UseForm2 and is finished. goes to item 2 and mods it as well. If he returns to item 1 to modify again say just to add into (column 2) ListBox1.List(ListIndex, 3), he has to input the information that the code placed into ListBox1.List(ListIndex, 4) and ListBox1.List(ListIndex, 1)

    The code for UserForm2

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!