Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2007

Tip: Looking for answers? Try searching our database.

Enable Command Button After Entering Text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mikeg710 - 28 Mar 2007 20:48 GMT
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!
mikeg710 - 29 Mar 2007 16:12 GMT
Ah!  After a bit more digging I found the solution in the Excel Programming
forum:

Subject: Re: 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!

> I am a beginner with Excel VBA programming and would greatly appreciate any
> advice on how to accomplish the following.
[quoted text clipped - 10 lines]
>
> Thank you in advance for any help on this question!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.