Userform Listbox Not Showing Updates

scgilbert1

New Member
Joined
Nov 15, 2011
Messages
13
Hello,

I have a userform with a multi-column listbox populated from a 2D array. The purpose of the userform is to allow the user to see and edit basic information for a list of clients using a combination of textboxes and checkboxes. The listbox is used to select a single client to view the data inputs for that client. When a client is selected, a group of textboxes and checkboxes are populated based on the data in the list (originally from the array). If the user makes any changes to the client data as tracked by the userform, it will ask if they want to save. If they say yes, the original data array is edited and the listbox should be updated to reflect the edits.

To populate the listbox, I have a single procedure that populates the list from the array data. I am using this procedure in the when the userform is initialized and when updates are made by the user.

However, I am running into an odd issue. When a user edits the data and I repopulate the listbox, the listbox itself doesn't initially reflect the changes and still reflects the original data. However, when I select the edited client from the list, the edited data shows correctly in the associated text boxes and check boxes as if the listbox had been changed but now it no longer matches. Every weirder, if I close the userform and reinitialize it, the listbox will then show the changes.

My current method to update the listbox is as follows.

colWidths = "15,60,60,20,20,20,20,20,50,50"

With Me.LB_Names
'.Clear
.List = clientList
.ColumnCount = UBound(clientList, 2)
.ColumnWidths = colWidths
End With

I commented out the ".clear"command because it would result in the listbox not being populated at all even though the backend data was updated properly. The clientList variable is an 2D Variant/Variant Array.

Thank you!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I'd say that it's because you are not refreshing the array. Would it not be better to reload the listbox from the sheet whose cells are (I assume) being edited by the userform textboxes? A solution might also depend on whether this is about a form control or ActiveX control. Best to always state which you're using, I'd say.
 
Upvote 0
I'd say that it's because you are not refreshing the array. Would it not be better to reload the listbox from the sheet whose cells are (I assume) being edited by the userform textboxes? A solution might also depend on whether this is about a form control or ActiveX control. Best to always state which you're using, I'd say.
I did go back and confirm that the underlying array is being updated by both printing out the contents to the immediate window and confirming the update in the locals window prior to the array be written to the list.

Here is what is stumping me. I run the code and the listbox disappears if I add ".clear" or doesn't update. I added a button to the userform with only the following code:

colWidths = "15,60,60,20,20,20,20,20,50,50"
With Me.LB_Names
.ColumnWidths = colWidths
End With

When I click the button, the list appears with the correct data. This is exactly the same code that is in the original listbox update code but it is just called separately. I did try to add this as a final "do this again last" call but it didn't work. It's like the userform had to reset something for it to work.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top