Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enabling a command only after text boxes are filled

Status
Not open for further replies.

dibya11

Programmer
Mar 18, 2003
7
IN
I need to enable a command button only after three text boxes are entered text into.Where do I write the code and what do I write. Please help.
 
you can try use the Validate event for each textbox, and need a boolean variable to enable the command
Set the TabStop property for the textboxes to True and the TabIndex property:

Private Form_Load()

Text1.TabIndex=0
Text2.TabIndex=1
Text3.TabIndex=2

End Sub

Private Sub Text1_Validate(Cancel As Boolean)

If Text1.Text="" then Cancel=true

End Sub

Private Sub Text2_Validate(Cancel As Boolean)

If Text2.Text="" then Cancel=true

End Sub

Private Sub Text3_Validate(Cancel As Boolean)

If Text1.Text="" then Cancel=true
Command1.Enabled=True

End Sub

This doesn´t prevent syntax errors, just checks the TextBoxes aren´t empty. If you want to Know more check Validate Event for TextBox in MSDN
 
In every form, I put in a sub called AdjustControls.
Private Sub AdjustControls()
I call this from every event that might affect other controls.

Call this from each Text_Changed Event
Private Sub AdjustControls()
cmd.Enabled = (Len(txt1.Text) > 0 and _
Len(txt2,text) > 0 and _
Len(txt3.Text) > 0)
End Sub

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
This is another way.

[tt]
Private Sub cmdDone_Click()
Dim ctl as Control

For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Text = "" Then
MsgBox "All fields must be entered."
Exit Sub
End If
Next ctl
[/tt]
 
Thank you all for your helps.
It worked all the ways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top