Enabled Property Example

This example enables a CommandButton control whenever a TextBox control contains text. To try this example, paste the code into the Declarations section of a form with CommandButton and TextBox controls, and then press F5 and enter something into the text box.

Private Sub Form_Load ()
   Text1.Text = ""   ' Clear the text box.
   Command1.Caption = "Save"   ' Put caption on button.
End Sub

Private Sub Text1_Change ()
   If Text1.Text = "" Then   ' See if text box is empty.
      Command1.Enabled = False   ' Disable button.
   Else
      Command1.Enabled = True   ' Enable button.
   End If
End Sub