0
votes

my question is in what event the submit button enable should be written if text boxes are filled, for VBA

for example im talking about the Private sub userform initialize()

i had created a userform where i used 2 frames. while the macro runs it initialize the first frame and user logins using that form to go the next form which is in the other frame.

in this second frame form i have 3 text box fields. only if the user inputs all the three text box then the command button should be enabled. im now stuck with in which event this code should be written.

Thank you

1
you could have the code associated with the command button verify the 3 text box fields are completed and then allow the program to continue otherwise end execution.QHarr
thanks i haven't thought of that.. thank you i will tryshakthivel sellapandiyan

1 Answers

1
votes

assuming the button is named after "CommandButton1" and the three textboxes are name after "TextBox1", "TextBox1" and "TextBox3", then in the Userform code pane add the following:

  • In UserForm_Initialize place:

    Me.CommandButton1.Enabled = False
    
  • add Change event handler for all those three textboxes

    Private Sub TextBox1_Change()
        checkEnableButton
    End Sub
    
    Private Sub TextBox2_Change()
        checkEnableButton
    End Sub
    
    Private Sub TextBox3_Change()
        checkEnableButton
    End Sub
    
  • finally add the following:

    Sub checkEnableButton()
        Me.CommandButton1.Enabled = Me.TextBox1.Value <> "" And Me.TextBox2.Value <> "" And Me.TextBox3.Value <> ""
    End Sub