+ Reply to Thread
Results 1 to 14 of 14

Multi combobox and class event on userform

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Multi combobox and class event on userform

    hi Guys,

    i am trying to use code from here:

    https://stackoverflow.com/questions/...-of-comboboxes

    but it is failing for me.

    i put 2 classes and in module i am just starting userform.
    What i am doing wrong?

    What i want to add also here is to get each combobox trigger after change and msgbox like "Combobox number is: "

    Thanks for help,
    Jacek
    Attached Files Attached Files

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Multi combobox and class event on userform

    You overlooked a fairly key statement at the top of the answer:

    In my demo I named the Userform -> FormComboGrid
    FormComboGrid is not a separate class module that you add, it's the userform.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Multi combobox and class event on userform

    Quote Originally Posted by jaryszek View Post
    What i want to add also here is to get each combobox trigger after change and msgbox like "Combobox number is: "
    I should add that the code in the link is unnecessarily complicated to achieve that.

    Also, more importantly, there aren't any comboboxes on your form...
    Last edited by romperstomper; 03-18-2022 at 06:26 AM.

  4. #4
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Multi combobox and class event on userform

    Thank you Rory,

    i would like to create these comboboxes automatically.
    Not create manually.

    thank you for a tip.
    Best,
    Jacek

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Multi combobox and class event on userform

    Here's a basic example. Userform code:

    Please Login or Register  to view this content.
    Class clsLineCopy:
    Please Login or Register  to view this content.
    Note you don't really need the mForm stuff for this but it might prove useful later depending on what you need to do, so I left it in.

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Multi combobox and class event on userform

    Thank you Rory,

    why i would need mForm stuff?

    Best,
    Jacek

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Multi combobox and class event on userform

    As with the example in the original link you posted, you might want the change events to call back to a routine in the form - it's a simple way of being able to access other controls on the form.

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Multi combobox and class event on userform

    Thanks!

    Rory i do not catch also:

    ComboBoxEventEnabled = True
    why to implement?

    and this one:

    myCommonCbo.Add Item:=cbo
    why to add comboboxes to collection if class will catch every change to them?

    Best,
    Jacek

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Multi combobox and class event on userform

    You don't need the first bit here.

    You have to add cbo (which is the class instance, not the combobox) to the collection otherwise it will lose its value when the Initialize code ends and none of your events will be handled. That is also why the collection is declared at module level, not in the Initialize code.

  10. #10
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Multi combobox and class event on userform

    thank you Rory!

    So generally collection stored comboboxes created and only With events work with declared objects witihin collection?

    Best,
    Jacek

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Multi combobox and class event on userform

    It doesn't have to be a Collection. You just need some means of storing the variables for each class instance so that they remain in scope when the initialization code ends.

  12. #12
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,314

    Re: Multi combobox and class event on userform

    form initialised with seventy comboboxes, the combobox values are intercepted by the class module.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  13. #13
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Multi combobox and class event on userform

    thank you!

    Jacek

  14. #14
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,314

    Re: Multi combobox and class event on userform

    thanks for the feedback and rep.

+ 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. [SOLVED] UserForm ComboBox event to trigger MsgBox
    By IGNF in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2018, 04:50 AM
  2. [SOLVED] Use info from class event, for Sub in userform
    By Un-Do Re-Do in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2018, 11:08 AM
  3. [SOLVED] Userform ComboBox Class Module not working
    By rodgersmg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2016, 03:23 AM
  4. [SOLVED] Populating a Multi column Combobox in a userform
    By anandvh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-14-2012, 04:11 PM
  5. [SOLVED] Basic userform multi combobox
    By crossy5575 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2012, 04:12 AM
  6. [SOLVED] I need a simple code for a click event using a UserForm ComboBox
    By Pyro Form in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2012, 07:58 AM
  7. [SOLVED] UserForm ComboBox Change Event Question
    By tja1964 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2012, 07:21 PM

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