+ Reply to Thread
Results 1 to 7 of 7

Userform ComboBox Class Module not working

  1. #1
    Forum Contributor
    Join Date
    10-11-2013
    Location
    Austria
    MS-Off Ver
    Excel 2010
    Posts
    136

    Userform ComboBox Class Module not working

    Good Morning all!

    I thought I'd add myself to the long list of people who have no idea about Class Modules but try to make one anyway.
    I set up a basic test file and copied some code in from various sources (from a Userfrom that I know works) and all runs with no apparent errors, but the class module doesn't trigger the events like it should.
    Heres the code, and I've attached the test file too

    Class Module (named cComb):
    Please Login or Register  to view this content.
    Userform:
    Please Login or Register  to view this content.
    Everything runs, but the message boxes don't show when they should. Can anyone spot my mistake(s)?
    Thanks in advance for the help

    Michael
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    06-04-2013
    Location
    Moscow
    MS-Off Ver
    Office 365
    Posts
    100

    Re: Userform ComboBox Class Module not working

    You must declare the c variable in Module(Insert - Module) as Public:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    I'm sorry my english...

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Userform ComboBox Class Module not working

    If that is the complete code, then the Collection only exists in the Userform_Initialize event so you lose all the event handlers as soon as that procedure exits.
    Declare the collection in the General Declarations section of the userform, before any executable code and then initialise it to a new collection when the userform loads.

    Please Login or Register  to view this content.
    Last edited by cytop; 05-24-2016 at 03:14 AM. Reason: Typo

  4. #4
    Forum Contributor
    Join Date
    10-11-2013
    Location
    Austria
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: Userform ComboBox Class Module not working

    Thanks to you both, that was it! i knew I needed the userform_initialize code from the for i copied everything from, but didn't think to look anywhere else
    Awesome! Thanks again.

  5. #5
    Forum Contributor
    Join Date
    10-11-2013
    Location
    Austria
    MS-Off Ver
    Excel 2010
    Posts
    136

    Re: Userform ComboBox Class Module not working

    Thanks to you both, that was it! i knew I needed the userform_initialize code from the for i copied everything from, but didn't think to look anywhere else
    Awesome! Thanks again.

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Userform ComboBox Class Module not working

    Just a comment re post #2

    If a public variable of type cComb is declared, then that will only refer to the last instance of the class that was instantiated in the UserForm_Load event. That is not a problem for this example, but it there were multiple comboboxes on the userform, only the last one would respond to the Change event.

    @The_Prist ... Sorry, but I think it best to clarify that point.

  7. #7
    Forum Contributor
    Join Date
    06-04-2013
    Location
    Moscow
    MS-Off Ver
    Office 365
    Posts
    100

    Re: Userform ComboBox Class Module not working

    cytop, you're right, first I changed the code, but then returned back and forgot change back PUBLIC to PRIVATE

+ 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 & Dynamic Controls & Class Module
    By sarndt01 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-18-2014, 01:53 PM
  2. Replies: 0
    Last Post: 03-08-2014, 08:02 AM
  3. KeyDown not working when Userform is loaded from a module
    By dordar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2014, 07:56 AM
  4. Replies: 1
    Last Post: 10-12-2012, 04:36 AM
  5. [SOLVED] ComboBox class .AddItem filled in class module
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-03-2012, 05:48 AM
  6. Class module with ActiveX ComboBox
    By oro77 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-01-2011, 09:16 PM
  7. Replies: 1
    Last Post: 08-30-2011, 02:23 AM

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