Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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
Posted to microsoft.public.excel.newusers
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Enable Command Button base on UserName | Excel Discussion (Misc queries) | |||
Is there a Wrap Text command button? | Excel Discussion (Misc queries) | |||
command button | Excel Worksheet Functions | |||
Can the Combo Box move and size with cells radio button be enable | Excel Worksheet Functions | |||
Command Button | Excel Discussion (Misc queries) |