+ Reply to Thread
Results 1 to 7 of 7

Using Class Module for handling events of dynamically created controls

  1. #1
    Registered User
    Join Date
    10-25-2007
    Location
    Melbourne, Australia
    Posts
    27

    Using Class Module for handling events of dynamically created controls

    Hi, All.
    I have a userform with a single blank multipage. At runtime additional pages are added, the number of pages depends on input from another userform. Six frames, containing labels, textboxes and comboboxes are then added to each page.
    I need to be able to use the textbox and combobox change events of these dynamically created controls to perform lookups and calculations. Although I can name the controls at the time they are created, it is not feasible to write code specifically for each control (I can have over 1,600 text boxes distributed over 9 pages, for example).
    Having searched for some time on how to achieve this I believe using a class module is the way to go. However, how to use a class module is just not sinking in I'm afraid.

    So far I have put the following code in a Class module called clsFormEvents:
    HTML Code: 
    In my UserForm module I have at the top:
    HTML Code: 
    Where I create the controls is the following:
    HTML Code: 
    When this runs I get "Compile error: Method or data member not found", so there is something I'm missing in setting all this up.

    I would really appreciate some guidance on how to use the class module to capture the change events of any instance of a specified control (specifically textboxes and comboboxes for my purpose).

    Grateful thanks in advance.
    Last edited by jagman; 03-04-2009 at 10:27 PM. Reason: Mark thread solved.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Using Class Module for handling events of dynamically created controls

    You need to create a reference between the added control and the class objects event handling control.
    Also you will need a collection to store multiple event handlers.

    Userform code
    Please Login or Register  to view this content.
    CUFTextbox class code
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-25-2007
    Location
    Melbourne, Australia
    Posts
    27

    Re: Using Class Module for handling events of dynamically created controls

    Andy,
    Thanks so much for your help.
    I have applied this method for both textboxes and comboboxes and it works fine across all pages and frames.
    Very much appreciated.
    John.

  4. #4
    Registered User
    Join Date
    06-02-2010
    Location
    Indian
    MS-Off Ver
    excel 2007
    Posts
    1

    Handling events of dynamically created controls not working for sheet.

    Hi
    The below solution is not working for Sheet wise code.I am trying to add command button for a sheet.I am able to create the buttons but the click event is not working.

    But the 674245.xls is based on Userform,the same code is not working in Sheet code.

    Please let me know your view.

    Link:

    http://www.excelforum.com/excel-prog...-controls.html

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Using Class Module for handling events of dynamically created controls

    rseeth01
    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

    Also,why a link back to this Thread?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    03-19-2015
    Location
    iraq
    MS-Off Ver
    2013
    Posts
    99

    Re: Using Class Module for handling events of dynamically created controls

    Andy Pope can you make a small modify on your file
    when change textbox1 fill in textbox2 any text

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Using Class Module for handling events of dynamically created controls

    Unfortunately your post does not comply with Rule 4 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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