Make a command button enabled

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abolos
    New Member
    • Apr 2007
    • 65

    #1

    Make a command button enabled

    Hello,

    I have an unbounded text box which have a default value of Zero (0). And a command button which is not enabled and will save the value in the text box when pressed.

    What I want is that: When I change the default value in the text box, I want the command button to be changeed to enabled. I want this action to be taken just when I start typing in the text box.

    Thank you for your help,
    Abolos
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    txtbox is called txt1, commmand button is called Command4

    Code:
    Private Sub Txt1_KeyPress(KeyAscii As Integer)
    	If Me.Txt1.Text & Chr$(KeyAscii) <> "0" Then Command4.Enabled = True Else Command4.Enabled = False
    End Sub

    Comment

    • abolos
      New Member
      • Apr 2007
      • 65

      #3
      Thanks for your reply. But actually it didn't work as I want. Because suppose you want to clear the text by backspace, then the button will stay active while it has to be inactive.

      But I found a solution for this. And it is:

      If Val(txt1.Text) > 0 Then
      Command4.Enable d = True
      Else
      Command4.Enable d = False
      End If


      Thanks anyway

      Comment

      • pks00
        Recognized Expert Contributor
        • Oct 2006
        • 280

        #4
        Ok, I did it on the understanding that u wanted it disabled when u had your default value of 0. To me it wasnt quite clear that u wanted it disabled when nothing was selected.

        Did u know already to use the Keypress function and also to use the .Text property and not .Value?

        Comment

        • abolos
          New Member
          • Apr 2007
          • 65

          #5
          Originally posted by pks00
          Ok, I did it on the understanding that u wanted it disabled when u had your default value of 0. To me it wasnt quite clear that u wanted it disabled when nothing was selected.

          Did u know already to use the Keypress function and also to use the .Text property and not .Value?

          Sorry for the delay and thanks for your reply. Yes i know the Keypress function.

          Abolos

          Comment

          Working...