+ Reply to Thread
Results 1 to 10 of 10

Control dynamically created Userform controls via class module

  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Control dynamically created Userform controls via class module

    Im going to have to ask this question because it will drive me mad for the weekend. I was trying to complete something for a forum member Thread here https://www.excelforum.com/excel-pro...-on-forms.html regarding changes to large numbers of controls.

    I've not much experience with class modules but got this far with code from web (attached workbook)

    This creates a set number of linked controls a checkbox, a textbox and a combobox

    I am trying to use the value of the checkbox to control what of the other two items is visible.

    I can isolate the integer and I know that the controls exist because I can list the exact names but I just cant address them. Tried many variations. The Code would have to be in the class Module. Any help appreciated

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by nigelog; 11-16-2018 at 01:13 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,068

    Re: Control dynamically created Userform controls via class module

    Add two more controls to the class as you did with the checkbox, then you can refer to those variables directly in your code.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Control dynamically created Userform controls via class module

    Hi Rory, as in
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,068

    Re: Control dynamically created Userform controls via class module

    The former, though they probably don't need to be declared WithEvents.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Control dynamically created Userform controls via class module

    Still no joy in using various methods of addressing
    Please Login or Register  to view this content.

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

    Re: Control dynamically created Userform controls via class module

    I made this change to your class.

    Please Login or Register  to view this content.
    First check will add text. Uncheck and txtbox and cbobox will be invisible. Check and they will appear.
    Cheers
    Andy
    www.andypope.info

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,068

    Re: Control dynamically created Userform controls via class module

    What I meant was:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Control dynamically created Userform controls via class module

    Hi Rory
    have tried addressing directly and have replaced all code with your above code and still no go, had to add the with to bring through value
    Please Login or Register  to view this content.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,068

    Re: Control dynamically created Userform controls via class module

    Sorry, yes, I got carried away deleting things. That will work assuming you assign the relevant controls to the class instance:

    Please Login or Register  to view this content.
    Last edited by romperstomper; 11-16-2018 at 12:54 PM.

  10. #10
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Control dynamically created Userform controls via class module

    Perfect, thanks Rory was a learning curve with class modules but rewarding.

+ 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. Using Class Module for handling events of dynamically created controls
    By jagman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2018, 01:14 PM
  2. Custom Class Module for multiple UserForm controls?
    By AnthonyGFS in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2018, 03:36 AM
  3. place dynamically created controls in row and column into the userform with in the frame
    By gokulkrishi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2016, 01:38 AM
  4. [SOLVED] Userform & Dynamic Controls & Class Module
    By sarndt01 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-18-2014, 01:53 PM
  5. [SOLVED] userForm -> Frame 'top' value limited. Dynamically created controls,
    By kropeck in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 08-19-2013, 09:04 AM
  6. Replies: 1
    Last Post: 10-12-2012, 04:36 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