+ Reply to Thread
Results 1 to 7 of 7

Listbox Empty When Form Loads After Using .additem

  1. #1
    Registered User
    Join Date
    07-20-2005
    Posts
    13

    Listbox Empty When Form Loads After Using .additem

    Hey all, back again adjusted my code and it seems to be working with one exception. I first have the code build a correlation table from a data set, from the correlation table certain variable pairs are selected and are to be added to a userform as a label and listbox. The listbox builds correctly when I step through the code but when the form itself loads the listboxes are empty.

    Here is my code:

    Please Login or Register  to view this content.
    I suspect its how I am displaying the form after it is created but I wanted to get some input.

    Thanks,

    ~J

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

    Re: Listbox Empty When Form Loads After Using .additem

    Hello jclark419,

    With complex code like this, it is easier and faster to troubleshoot if you post your workbook. This saves a lot time by not having to try to recreate the data needed to test the code.
    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!)

  3. #3
    Registered User
    Join Date
    07-20-2005
    Posts
    13

    Re: Listbox Empty When Form Loads After Using .additem

    Sorry about that, I had to clean up some of the proprietary stuff out of the workbook before uploading it.

    Thanks

    ~J
    Attached Files Attached Files

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

    Re: Listbox Empty When Form Loads After Using .additem

    Hello jclark419,

    Turns out the problem with the ListBoxes is they have to be loaded during runtime. To do that, the UserForm needs to have the code to load the ListBoxes in the UserForm_Initialize() event. To illustrate how this works, I have included a text file which is opened by the macro. The file contains code to load MyListBox1 with the numbers from1 to 10.
    Please Login or Register  to view this content.
    The UserForm_Initialize() event code is loaded before the UserForm is shown. Once this event code is loaded, the UserForm will remain in the project. You need to add code to the workbook to remove the UserForm from the workbook when it is saved.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Listbox Empty When Form Loads After Using .additem

    ~J, this is the same advice given in your other post!

    http://www.excelforum.com/excel-prog...d-in-code.html
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    07-20-2005
    Posts
    13

    Re: Listbox Empty When Form Loads After Using .additem

    Leith, thanks for the response. I will work with it today and hopefully get it to work.

    Andy, I was hoping that by changing the order of my code that it would somehow fix the building/running of the userform because I didn't really understand the difference between design and runtime. I do apologize for the double post though.

    Thanks both of you for the help, now maybe I can make some progress again!

    ~J

  7. #7
    Registered User
    Join Date
    07-20-2005
    Posts
    13

    Re: Listbox Empty When Form Loads After Using .additem

    Alright so it seems to be going in the right direction of what I need but I have another question. In the UserForm_Initialize code I am trying to have it populate the listboxes that were created earlier. Each of this listboxes was numbered in a loop (i.e. MyListBox1, MyListBox2 ...) but the number of list boxes will vary based on the data set provided.

    I was going to use nested loops to populate with the correct data but it gives me an error. I am including the files again. The code I have written in the UserForm_Initialize file is incorrect but I wanted to give you an idea of what I did.

    Thanks again,

    ~J
    Attached Files Attached Files

+ 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