Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 8
Default Enable Command Button After Entering Text

I am a beginner with Excel VBA programming and would greatly appreciate any
advice on how to accomplish the following.

I created a user form with three text boxes (txtName, txtDescription,
txtProcess) and two command buttons (cmdAdd, cmdCancel). I do not want the
cmdAdd button enabled until a user enters valid text into both the txtName
AND txtDescription text boxes. I have the Enabled property for the cmdAdd
button set to False.

How and where do I code the procedure to set the cmdAdd control's Enabled
property to True as soon as the user has entered valid text in BOTH the
txtName and txtDescription controls?

Thank you in advance for any help on this question!
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 8
Default Enable Command Button After Entering Text

Ah! After a bit more digging I found the solution in the Excel Programming
forum:

Subject: UserForms, mandatory completion of fields 1/13/2006 8:51 AM
PST

By: Dave Peterson In: microsoft.public.excel.programming


Another option would be to keep the ok button disabled until all your fields
are
ok:

Option Explicit
Private Sub TextBox1_Change()
Call CheckAllRules
End Sub
Private Sub TextBox2_Change()
Call CheckAllRules
End Sub
Private Sub TextBox4_Change()
Call CheckAllRules
End Sub
Private Sub UserForm_Initialize()
Me.CommandButton1.Enabled = False
End Sub
Private Sub CheckAllRules()
Dim myCtrl As Control
Dim OkToEnable As Boolean

OkToEnable = True
For Each myCtrl In Me.Controls
If TypeOf myCtrl Is MSForms.TextBox Then
If myCtrl.Object.Value = "" Then
OkToEnable = False
Exit For
End If
End If
Next myCtrl

Me.CommandButton1.Enabled = OkToEnable

End Sub


Reposting the info here for anyone else who may need it. Thank you!

"mikeg710" wrote:

I am a beginner with Excel VBA programming and would greatly appreciate any
advice on how to accomplish the following.

I created a user form with three text boxes (txtName, txtDescription,
txtProcess) and two command buttons (cmdAdd, cmdCancel). I do not want the
cmdAdd button enabled until a user enters valid text into both the txtName
AND txtDescription text boxes. I have the Enabled property for the cmdAdd
button set to False.

How and where do I code the procedure to set the cmdAdd control's Enabled
property to True as soon as the user has entered valid text in BOTH the
txtName and txtDescription controls?

Thank you in advance for any help on this question!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable Command Button base on UserName Doctorjones_md Excel Discussion (Misc queries) 6 April 20th 07 07:16 PM
Is there a Wrap Text command button? Álvaro Excel Discussion (Misc queries) 5 December 1st 06 05:21 PM
command button wayno Excel Worksheet Functions 1 July 31st 06 02:02 AM
Can the Combo Box move and size with cells radio button be enable Tom Cote Excel Worksheet Functions 0 September 5th 05 09:27 PM
Command Button Chris Hale Excel Discussion (Misc queries) 1 February 10th 05 05:14 AM


All times are GMT +1. The time now is 09:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"