AfterUpdate for listboxes

Mozzie

Registered User.
Local time
Today, 21:29
Joined
Jul 5, 2014
Messages
10
Hi all,

I have several listboxes on an MS Access form in VBA. At the moment, I use a listboxname_AfterUpdate to pass the value of the listbox selection to the tag of a button, so that when the button is clicked the value of current listbox selection is known and can be used within the buttonname_click sub.

Is there another way this can be done? I would prefer the listboxes are dynamically created (their names are based upon categories retrieved from Outlook, which can be added to over time) to avoid having to create a listboxname_AfterUpdate for every single category. I looked into WithEvents, but sadly this does not support AfterUpdate.

Regards,

Mozzie
 
What exactly are you trying to do in plain English? Forget the listbox, button, tag and Outlook, and afterUpdate jargon for the moment.
 
And why would you need to save the value in a tag?
 
And why would you need to save the value in a tag?

Multiple list boxes and one button. I need to use whatever value is selected in the listbox when the button is clicked. This was my way of telling the button which listbox has a selected item.

I achieved what is required (an after update that works for every listbox, regardless of name) by using the Form_Open sub to assign a single AfterUpdate function to every listbox with the listbox.name as parameter.
 
You would have saved yourself all that hassle, if you had asked how to achieve that in the first place. Have a look at the ItemsSelected collection of a listbox in the following link:

I had looked at ItemsSelected, but it looked like I would need to know the listbox name, which is what I was trying to avoid doing.
 
Yes you would but you could have named your listbox and button appropriately.

Button1: btnCategories
Listbox1: lstCategories

Code:
Code:
Me.Controls("lst" & Mid(Me.btnCategories.Name)).ItemsSelected
 
Yes you would but you could have named your listbox and button appropriately.

Button1: btnCategories
Listbox1: lstCategories

Code:
Code:
Me.Controls("lst" & Mid(Me.btnCategories.Name)).ItemsSelected
Oops, sorry, I missed this post.

I would need a button per category then I think?
 
No. There's a miscommunication! Can you upload a cut-down version of your db so that I can see what you're trying to do.
 

Users who are viewing this thread

Back
Top Bottom