Consulting

Results 1 to 2 of 2

Thread: VBA listbox change event

  1. #1

    VBA listbox change event

    Hi everyone,

    I have a userform that contains 3 listboxes. This is userform1

    To populate the listbox1 I click a commandbutton1 that takes me to a second userform (userform2). From here I select the data from another listbox4 (multiselect). Once I click the commmandbutton2 on userform2 it populates listbox1 with the selected data. It also adds lookup values to listbox2 based on the values added to listbox1 via a series of for loops.

    This all works fine so far. Now I need Listbox3 to be populated based on selected data from Listbox 2. I have achieved this by making a Listbox2_change() routine and this also works well.

    My problem is that it seems the listbox2_change event is triggered every time values are added to listbox2 when the CommandButton2 is clicked on userform2. I thought the solution would be to enclose the commandbutton2 routine with:

    Application.EnableEvents = False

    code...

    Application.EnableEvents = True

    But the listbox2_change event is still running? Does anyone know what I am doing wrong here?

    Apologize if the wording is confusing....

    list of objects

    userform1
    -listbox1
    -listbox2 (multi select)
    -listbox3 (multi select)
    -commandbutton1

    userform2
    -listbox4 (multiselect)
    -commandbutton2

  2. #2
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    Don't worry
    you aint the only one with thinning hair

    the trick is to use
    me.enableevents=true
    'me' references the parent object of the form or control you are on. it seems to be that the userform is different to the application - and this is why application.enableevents does not work.

    werafa
    Remember: it is the second mouse that gets the cheese.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •