Help Disabling Controls On UserForm based on ComboBox In Another UserForm

  • Hello this is my first time writing code so I apologize for how clumsy my code must look.

    I have a UserForm(NewProposal) with a Command button (called Customize1, or 2, etc) and a ComboBox(called year 1, etc. - drop down has a range of 1 to 5). The same comboBoxes and command buttons are repeated multiple times with the trailing number just changing. (The names end with a 1, or 2, etc.)

    When the command button is clicked it opens up a second userform(CustomizeCosts) with multiple Text Boxes, labels, and comboboxes.

    Essentially I want the second userform (CustomizeCosts) to determine which command button called it, and based on that to pull the value of the corresponding combo box. If they chose contract length (years1 combo box) as 1, than I want all the controls on the second form that end with 2-5 to be disabled.

    If CommandBox 2 was clicked it would pull the value from combobox2(Years2) and determine which controls should be disabled based on that.

    On userform1 i set up a Public WhatsClicked As Integer

    The commandbutton 1 code is:

    I have gotten the code to run error free, however none of the controls in the UserForm CostomizeCosts actually end up being disabled.... What am i doing wrong?

    Thank You for your help! :)

  • Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post

    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.

    How to use code tags

    Just highlight all of the code and press the <> in the post menu above button to add the code tags.


  • There's a lot of code to work through, without any notes added, to try to understand what you are doing.

    I think you complicating it. I can't see why you need multiple userforms and controls, you have 4 year textboxes. Will you use them all or multiples in one customisation?

    To link the two userforms you need to use code like this,

    Me.UserForm.TextBox1.value =Me.UserForm2.ComboBox1.value

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!