Disabling Buttons

until text has been typed in

Page 1 of 1

5 Replies - 606 Views - Last Post: 25 March 2009 - 11:21 PM Rate Topic: -----

#1 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Disabling Buttons

Posted 25 March 2009 - 12:29 AM

hi
i am trying to disable a button when text has not been typed in and once the some text has been typed in, the button is enabled. the code i have is not doing what i want it to instead it disables the button forever.
can anyone help??
If txtInvest.Text = "" Then
cmdCompute.Enabled = False
ElseIf txtInvest.Text > 0 Then
cmdCompute.Enabled = True
End If


This post has been edited by firebolt: 25 March 2009 - 12:30 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Disabling Buttons

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: Disabling Buttons

Posted 25 March 2009 - 12:39 AM

Make sure you're placing the If statement inside the Change event of the textbox.

Now, here's the If statement to use:

If txtInvest.Text = "" Then
    cmdCompute.Enabled = False
ElseIf txtInvest.Text <> "" Then
    cmdCompute.Enabled = True
End If


The trick here is that "<>" means "not equal to" in VB.
Was This Post Helpful? 0
  • +
  • -

#3 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: Disabling Buttons

Posted 25 March 2009 - 01:19 AM

I understand what you are doing but the button still is disabled even when you start typing in text. Any answers??

And does this go under Private Sub Form_Load() ??

This post has been edited by firebolt: 25 March 2009 - 01:22 AM

Was This Post Helpful? 0
  • +
  • -

#4 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: Disabling Buttons

Posted 25 March 2009 - 03:07 AM

It's because you're putting it in the wrong event.

Put it in the txtInvest_Change() sub.

Private Sub txtInvest_Change()
    If txtInvest.Text = "" Then
        cmdCompute.Enabled = False
    ElseIf txtInvest.Text <> "" Then
        cmdCompute.Enabled = True
    End If
End Sub

Was This Post Helpful? 1
  • +
  • -

#5 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: Disabling Buttons

Posted 25 March 2009 - 10:08 PM

Thanks. This works great!
Was This Post Helpful? 0
  • +
  • -

#6 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: Disabling Buttons

Posted 25 March 2009 - 11:21 PM

You're welcome.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1