+ Reply to Thread
Results 1 to 8 of 8

User Form Listbox.Rowsource Problem and Solution

  1. #1
    Registered User
    Join Date
    03-19-2016
    Location
    Long Island
    MS-Off Ver
    2016
    Posts
    3

    Red face User Form Listbox.Rowsource Problem and Solution

    Hi, This is my first post - registered yesterday. I fully expected to be asking for help but figured it out this morning and wanted to share.

    Problem: Attempting to add a row to an Excel table via module code that is invoked from a command button on user form. Excel crashes.

    Using ListObject.ListRows.Add method

    Error: "The object invoked has disconnected from its clients" - followed by Excel crashing in ill humor.

    Description.

    My application has a combo box and list box on a user form.
    • Combo box has a list of product types populated from Excel table via RowSource of combo box.
    • ListBox has RowSource set to item selected in combo box. The values in combo box are the names of a bunch of tables. One for each product type all have same column structure.

    Today I decided to take a line from the movie "The Princess Bride" and "go back to the beginning".
    • I Created a new workbook dumbed it down with one table and a macro and added the row via macro, no problem.
    • Next, Added a user form with a button tied to macro and code executed again with no issues.
    • Added a list box to the user form and set RowSource to table and bang back to the the big crash when I run the macro.
    • Something is up with ListBox being connected to table. Next, I set RowSource to "" before I invoke"Add" macro and everything works beautiful. I set the RowSource back after the "Add" succeeds and List box is updated with added row.

    I don't know if this is a bug in Excel but sure seems like it. I have been programming for 30+ years and I was about to give up thinking Excel is just not stable for this type of program.

    Anyway. I would love to hear some opinions on this and hope the info is helpful to others.

    Thanks for listening.

    John

  2. #2
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: User Form Listbox.Rowsource Problem and Solution

    Show the file with the form
    Don't use RowSource and work with arrays.
    Last edited by kalbasiatka; 03-20-2016 at 03:14 PM.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

  3. #3
    Registered User
    Join Date
    03-19-2016
    Location
    Long Island
    MS-Off Ver
    2016
    Posts
    3

    Question Re: User Form Listbox.Rowsource Problem and Solution

    File is attached - Form is displayed by Ctrl-Shift+M

    I Might add I am using Excel 2016 Pro (Office 365) and Windows 10 Enterprise

    Look at Code for ProdManager form in the Add button.

    Thanks
    John
    Attached Files Attached Files

  4. #4
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: User Form Listbox.Rowsource Problem and Solution

    It is better to base as a base and not a lot of tables. Not saying that my version is better but I do so.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-19-2016
    Location
    Long Island
    MS-Off Ver
    2016
    Posts
    3

    Re: User Form Listbox.Rowsource Problem and Solution

    I think your version is cleaner/better and will try to use these techniques - you are doing a few things I will try to understand.

    Thanks for taking the time to provide this version.

  6. #6
    Registered User
    Join Date
    04-04-2020
    Location
    Bradenton, FL, USA
    MS-Off Ver
    Office 365 MSO 32-Bit
    Posts
    1

    Re: User Form Listbox.Rowsource Problem and Solution

    I had this Excel crash problem as well. It seems the crash was caused by having the Listbox.RowSource set to the table or range while the code was doing the update work to that table or range.

    The crash stopped when I set the Listbox.RowSource to "", updated the data, and then reconnected the Listbox.RowSource to the range. I am actually setting the RowSource = to a ListObject.

  7. #7
    Registered User
    Join Date
    01-10-2022
    Location
    Guatemala
    MS-Off Ver
    365
    Posts
    1

    Re: User Form Listbox.Rowsource Problem and Solution

    Edward, thank you so much!
    I was having this problem and I'm not too familiar with VBA and was desperate haha. I used your solution in the "add" button code and works perfectly. It doesn't crash anymore.

  8. #8
    Registered User
    Join Date
    01-31-2024
    Location
    Home
    MS-Off Ver
    Office 365
    Posts
    14

    Re: User Form Listbox.Rowsource Problem and Solution

    Quote Originally Posted by EdwardMartin View Post
    I had this Excel crash problem as well. It seems the crash was caused by having the Listbox.RowSource set to the table or range while the code was doing the update work to that table or range.

    The crash stopped when I set the Listbox.RowSource to "", updated the data, and then reconnected the Listbox.RowSource to the range. I am actually setting the RowSource = to a ListObject.
    Hello, I am sorry for necroing the thread - how exactly does one do that? I am having the exact same issue, using listbox Rowsource and having runtime error.

    Please Login or Register  to view this content.
    So I should have "" instead of "rg.Address(external:=True)", and then somehow update it afterwards? How?

    Thank you for any help.
    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)

Similar Threads

  1. User Form ListBox - Find Records (ListBox Populating Issue)
    By LONeillSSC in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-20-2015, 12:06 PM
  2. Listbox Update on user form
    By Irish_Griffin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-15-2009, 02:41 PM
  3. Functional Listbox in User Form
    By warby23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2009, 05:17 AM
  4. populating a listbox on a user form?
    By lrhodes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2006, 07:05 PM
  5. [SOLVED] RowSource for User Form
    By Klatuu in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-23-2006, 06:30 PM
  6. Listbox RowSource problem
    By Casey in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2006, 05:10 PM
  7. [SOLVED] [SOLVED] Listbox.RowSource problem
    By Tim Coddington in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-08-2005, 08:06 PM

Tags for this Thread

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