+ Reply to Thread
Results 1 to 8 of 8

ListBox refuses to repopulate after selection change

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    ListBox refuses to repopulate after selection change

    Hi,

    How do I automatically update a ListBox on a UserForm after changing a TextBox whose value is on that ListBox?

    I have two UserForms, Userform1 requires the user to click an "Amend Record" button to update the ListBox (and the underlying database). That works perfectly (it's on sheet "Database"). But now I need to make the updates without having to press any buttons. The ListBox (on Userform2") and Database2 need to update automatically. And I have been successful with all the controls except for the one whose value appears in the ListBox.

    Whenever I mention that control ("txtName") in the code, the ListBox refuses to populate itself whenever a user changes a ListBox selection. The problem seems to be that the code runs the populate macro when the form is initialized, but then when a ListBox selection is made, the code reads the List range range as empty.

    I've tried all sorts of solutions to get the list range to be read again, but no luck. What do you think?

    Lawrence

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: ListBox refuses to repopulate after selection change

    Your code seems to run extremely slowly.

    The Named Ranges seem to be created with complicated formulas? Why?

    I can't see why you need those names to populate the ListBoxes
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: ListBox refuses to repopulate after selection change

    RoyUK,

    Which complicated range names? All of the range names used in the macros refer to single cells except for the dynamic range referring to the database, "ListItemsRange2".

    If I replace the dynamic formula with a fixed range, I still get the same problem of the ListBox not repopulating.

    Slow? That's wierd! It's getting suck on rngMove on the spinner macro...never did that before. I'll try to resolve that.

    What do you think is the issue with repopulating the Listbox?

    Lawrence





    Quote Originally Posted by royUK View Post
    Your code seems to run extremely slowly.

    The Named Ranges seem to be created with complicated formulas? Why?

    I can't see why you need those names to populate the ListBoxes

  4. #4
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: ListBox refuses to repopulate after selection change

    Okay, I rebooted my PC and now I do not experience any lag.

    Wish I knew what lag you were experiencing.

    Any ideas on the populating ListBox issue?

    Lawrence

  5. #5
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: ListBox refuses to repopulate after selection change

    ...Bump...

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: ListBox refuses to repopulate after selection change

    Have you run your Populate ListBox procedure?

  7. #7
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: ListBox refuses to repopulate after selection change

    Hi RoyUK,

    Yes, if there is any references to the control txtName in the ListBox_Click macro on UserForm2, the Populate macro will only work when the form is initialized/activated and will fail when selecting an item in the ListBox. Using step-in, Populate reads the range for the list, but the ListBox remains empty.

    What do you think?

    Lawrence
    Last edited by skysurfer; 01-03-2011 at 01:24 PM.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: ListBox refuses to repopulate after selection change

    Hello Lawrence,

    You need to move your code from the txtName_Change() event to the txtName_AfterUpdate() event. I have done this in the attached workbook.
    Last edited by Leith Ross; 01-04-2011 at 02:27 AM. Reason: Attached workbook
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1