hello
i want to know How to enabling a command only after text boxes are filled
in VB6
hello
i want to know How to enabling a command only after text boxes are filled
in VB6
Try this
ORCode:Private Sub Text1_Change() If Text1.Text = vbNullString Then Command1.Enabled = False Else Command1.Enabled = True End If End Sub
Code:Private Sub Text1_Change() Command1.Enabled = Not (Text1.Text = vbNullString) End Sub
this would work alsoCode:Private Sub Text1_Change() Command1.Enabled = Len(Text1.Text) End Sub
If there are several textboxes the you could iterate thru the form's controls (Controls Collection)
Declare a boolean... set it to true
Inside the loop
Ask if it is textbox (TypeOf Is Textbox) and if it's filled... set the boolean to false if empty
...
Outside of the loop
Ask for the boolean variable
If it is true then enable command button
JG
... If your problem is fixed don't forget to mark your threads as resolvedusing the Thread Tools menu ...
This is VB6 forumAsk if it is textbox (TypeOf Is Textbox)![]()
TypeOf is a valid keyword in VB6
The next piece of code changes the forecolor of all Text Box controls on Form1 to red:
You'll also find this approach useful for many other tasks, such as unchecking all of the CheckBox controls.Code:Dim c As Control For Each c In Form1.Controls If TypeOf c Is TextBox Then c.ForeColor = vbRed End If Next
JG
... If your problem is fixed don't forget to mark your threads as resolvedusing the Thread Tools menu ...
In form load make command button disabled. In each textbox's change event check for emptiness (Len(Text...)=0) of all text boxes, if any one is empty keep Command Button disabled.
Along the same lines as Smartchap, you can grab the length of a series of textboxes and multiply those lengths together. If any textbox is empty, it will equate to 0 and any number multipled by 0 becomes 0 and 0 will equate to False. Example:Code:Option Explicit Private Sub EnableButton() Command1.Enabled = Len(Text1.Text) _ * Len(Text2.Text) _ * Len(Text3.Text) _ * Len(Text4.Text) _ * Len(Text5.Text) End Sub Private Sub Command2_Click() EnableButton End Sub
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.
Creating A Wizard In VB.NET
Paging A Recordset
What is wrong with using On Error Resume Next
Good Article: Language Enhancements In Visual Basic 2010
Upgrading VB6 Code To VB.NET
Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked
hello all
thanks for all but i want that the command button disabled at default then enabled after After writing anything on textbox
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.
Creating A Wizard In VB.NET
Paging A Recordset
What is wrong with using On Error Resume Next
Good Article: Language Enhancements In Visual Basic 2010
Upgrading VB6 Code To VB.NET
Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked
hello
yes i've tried it but the problem is that the command button shift to disabled after writing anything on textbox and clean it
i'm loocking for any way to disable the command button at default
for exemple if you open my program you will see the command button disabled at default
Set Enabled = False in design mode, on the button's property page.
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.
Creating A Wizard In VB.NET
Paging A Recordset
What is wrong with using On Error Resume Next
Good Article: Language Enhancements In Visual Basic 2010
Upgrading VB6 Code To VB.NET
Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked
thanks so much
now it work but there is a small mistake
i've 3 textbox after writing anything on one textbox, the command button shift to Enabled without considering the two other textbox
this is the codethat i've used from 4x2y:
Code:Private Sub Text1_Change() If Text1.Text = vbNullString Then calculateBtn.Enabled = False Else calculateBtn.Enabled = True End If End Sub Private Sub Text2_Change() If Text2.Text = vbNullString Then calculateBtn.Enabled = False Else calculateBtn.Enabled = True End If End Sub Private Sub Text3_Change() If Text3.Text = vbNullString Then calculateBtn.Enabled = False Else calculateBtn.Enabled = True End If End Sub
Or he can do it like this:
Code:Private Function EnableButton() As Boolean EnableButton = Len(Text1.Text) _ * Len(Text2.Text) _ * Len(Text3.Text) _ * Len(Text4.Text) _ * Len(Text5.Text) End Function 'In Every Change-Event of the particular TextBoxes: Private Sub Text1_Change() Command1.Enabled = EnableButton End Sub 'The same in Form_Load-Event Private Sub Form_Load() Command1.Enabled = EnableButton End Sub
For health reasons i try to avoid reading unformatted Code
To stay in your example:
vb Code:
Private Function EnableButton() As Boolean EnableButton = Len(Text1.Text) * Len(Text2.Text) * Len(Text3.Text) End Function Private Sub Text1_Change() Command1.Enabled = EnableButton End Sub Private Sub Text2_Change() Command1.Enabled = EnableButton End Sub Private Sub Text3_Change() Command1.Enabled = EnableButton End Sub
For health reasons i try to avoid reading unformatted Code
What is the error message?