AfterUpdate Listbox.ItemsSelected works but not Form_Load Listbox.ItemsSelected

Nothnless

Board Regular
Joined
Apr 28, 2016
Messages
142
I Have 2 ListBoxes, Listbox1 has Row Source from a table but Listbox2's Row Source depends upon what is selected in Listbox1. Everything works fine as expected using AfterUpdate for Listbox1 event. However, once I leave the form and come back Listbox1 still has it's selections but Listbox2 is now blank. I want to keep what was in Listbox2 since Listbox1 still has selections.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The title of your post is the only clue I get from what you posted. You cannot deal with listbox selections in the form Load event. That event only happens after the form opens and only once until closed then opened again. However, I don't see how that fits in with selecting a different form then coming back to this one that is still open, yes? Not clear what "leave the form" means, but I take it to mean it loses the focus, not that you closed it. If you're not closing the form lstbox2 row values should remain unless subsequent code is doing something to them. How are you populating lstbox2 rows - value list from lstbox1 itemsSelected?
 
Upvote 0
Solution
Hi, no I am actually closing the form and then coming back to it. So I guess I just shouldn't close the form, I can just hide it instead. Okay that's an easy solution for my purposes however the underlining issue that confused me was as to why Access no longer recognizes the ListBox Items when reopened. If I close the form and open it back up ListBox1 still has it's previously selected items. I guess this is just because its bound to a table.
 
Upvote 0
Unbound controls cannot hold their values when the form is closed so yes, you have figured out the cause. The one exception would be if the control source property is set to something that is either static or is the result of an expression; e.g. = 5 or = 5*2. Such an expression could not depend on other unbound/missing values.
 
Upvote 0

Forum statistics

Threads
1,221,522
Messages
6,160,313
Members
451,637
Latest member
hvp2262

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