Results 1 to 1 of 1

Enabling/disabling dynamically generated control via another dynamically generated control

Threaded View

keaden Enabling/disabling... 10-04-2018, 05:46 AM
  1. #1
    Registered User
    Join Date
    11-12-2011
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    6

    Enabling/disabling dynamically generated control via another dynamically generated control

    I have a userform that creates a new multipage with each press of a button.
    Each multipage will contain a number of dynamically created controls (textboxes, optionbuttons comboboxes etc)
    Some of these dynamic controls must be Enabled/disabled via the selection or input values from other dynamically created controls.

    So far here is my code for the project is as follows;

    Option Explicit
    Private x As Integer
    
    Private Sub UserForm_Initialize()
    x = 1
    End Sub
    
    Private Sub Cmd1_Click()
    
    Dim OpPage As MSForms.Page
    Dim Page1 As MSForms.MultiPage
    Dim tankNameTxt As Control
    Dim textYesNo1 As Control
    Dim radioYes As Control
    Dim radioNo As Control
    Dim radio As Control
    
    If x > 0 Then
    
    Set OpPage = UserForm1.MultiPage2.Pages.Add("Tank Number " & x)
    Set tankNameTxt = UserForm1.MultiPage2.Pages(x).Controls.Add("Forms.TextBox.1", "Tank" & x, True)
    Set textYesNo1 = UserForm1.MultiPage2.Pages(x).Controls.Add("Forms.TextBox.1", True)
    Set radioYes = UserForm1.MultiPage2.Pages(x).Controls.Add("Forms.OptionButton.1", "radioYes" & x, True)
    Set radioNo = UserForm1.MultiPage2.Pages(x).Controls.Add("Forms.OptionButton.1", "radioNo" & x, True)
    Set radio = UserForm1.MultiPage2.Pages(x).Controls.Add("Forms.OptionButton.1", "radio" & x, True)
    
    With OpPage
    .KeepScrollBarsVisible = 2
    .ScrollBars = 2
    .ScrollHeight = 500
    End With
    
    With tankNameTxt
    .MultiLine = False
    .WordWrap = True
    .AutoSize = True
    .ScrollBars = 2
    .Left = 10
    .Top = 15
    .BorderStyle = 1
    .SelectionMargin = False
    .SpecialEffect = 0
    .Height = 15
    .Text = "Tank " & x & " Name"
    End With
    
    With radioYes
    .Caption = "Is Yes"
    .GroupName = "YesNo"
    .Left = 10
    .Top = 45
    End With
    
    With radioNo
    .Caption = "Is No"
    .GroupName = "YesNo"
    .Left = 50
    .Top = 45
    End With
    
    With textYesNo1
    .Name = "textYesNo" & x
    .BackStyle = 0
    .BorderStyle = 0
    .SpecialEffect = 0
    .Value = "Yes No " & x
    .Left = 3
    .Locked = True
    .Top = 35
    .Height = 30
    .Width = 80
    End With
    
    With radio
    .Caption = "Is Disabled?"
    .GroupName = "otherControl"
    .Left = 50
    .Top = 65
    End With
    'MsgBox "radio is " & radio.Name
    x = x + 1
    
    End If
    
    End Sub
    
    Private Sub radioYes_Click()
    
    If UserForm1.MultiPage2.Pages(x).radioYes.Value = True Then
    UserForm1.MultiPage2.Pages(x).radio.Enabled = True
    ElseIf UserForm1.MultiPage2.Pages(x).radioNo.Value = True Then
    UserForm1.MultiPage2.Pages(x).radio.Enabled = False
    End If
    
    End Sub
    Problem
    The iteration of x through the project and the use of integer x in the naming of the dynamically generated controls have me at a loss as to how to create code to affect the dynamically generated controls or even how to properly name the declarations for a Sub.

    For instance

    Private Sub radioYes_Click()
    OR

    Private Sub radioYes1_Click()
    do not seem to work of have any effect on the controls I want to enable/disable.

    I suspect this issue may be solved by the use of a Class but I frankly need help in understanding classes and their use in vba.

    Any help on this would be appreciated.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to click on a dynamically generated hyperlink
    By Wonderingaboutmacros in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2017, 09:15 AM
  2. Dynamically generated Shell command
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2016, 02:31 PM
  3. How to Create Dynamically Generated Word List
    By GoodManRob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-28-2014, 11:24 AM
  4. Dynamically Generated Form And Their Click Events
    By fenilbhoot in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-12-2013, 10:13 AM
  5. [SOLVED] Use VBA to download a dynamically generated image from the web.
    By nponoBegHuk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2012, 09:51 AM
  6. Setting up a dynamically generated range reference
    By cveetan in forum Excel General
    Replies: 8
    Last Post: 02-22-2012, 07:37 AM
  7. Dynamically Generated Range using Macro
    By JM.EE01@gmail.com in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-15-2006, 03:15 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