Author |
Message |
Cube #1 / 10
|
 Simple Question
Hi, I have a form with a two text boxes: txtUserName and txtPassword, i also have a two command buttons: cmdSubmit and cmdCancel. The cmdSubmit is disabled by default, how can I enable it programmatically when the two text boxes have been filled with valid data (say for example 7 characters in txtUserName and 8 characters in txtPassword). Thank you, Cube
|
Mon, 08 Dec 2003 18:25:18 GMT |
|
 |
Alexander Shirsho #2 / 10
|
 Simple Question
Write code in textboxes Change procedures: Private Sub txtUserName_Change() cmdSubmit.Enabled = Len(txtUserName.Text)=7 End Sub -- HTH, Alexander Shirshov, MCSD
Quote: > Hi, > I have a form with a two text boxes: txtUserName and txtPassword, i also > have a two command buttons: cmdSubmit and cmdCancel. > The cmdSubmit is disabled by default, how can I enable it programmatically > when the two text boxes have been filled with valid data (say for example 7 > characters in txtUserName and 8 characters in txtPassword). > Thank you, > Cube
|
Mon, 08 Dec 2003 18:26:53 GMT |
|
 |
Cube #3 / 10
|
 Simple Question
Thank you Alexander but I meant the two textboxes have to contain valid data. Sorry for not making my question clear the first time.
Quote: > Write code in textboxes Change procedures: > Private Sub txtUserName_Change() > cmdSubmit.Enabled = Len(txtUserName.Text)=7 > End Sub > -- > HTH, > Alexander Shirshov, MCSD
> > Hi, > > I have a form with a two text boxes: txtUserName and txtPassword, i also > > have a two command buttons: cmdSubmit and cmdCancel. > > The cmdSubmit is disabled by default, how can I enable it programmatically > > when the two text boxes have been filled with valid data (say for example > 7 > > characters in txtUserName and 8 characters in txtPassword). > > Thank you, > > Cube
|
Mon, 08 Dec 2003 19:16:26 GMT |
|
 |
Alexander Shirsho #4 / 10
|
 Simple Question
What is valid data? Anyway, you can check the contents of both textboxes in this sub and enable the button if it meet your criteria. My example enables the button if txtUserName contains exactly 7 characters. -- HTH, Alexander Shirshov, MCSD
Quote: > Thank you Alexander but I meant the two textboxes have to contain valid > data. Sorry for not making my question clear the first time.
> > Write code in textboxes Change procedures: > > Private Sub txtUserName_Change() > > cmdSubmit.Enabled = Len(txtUserName.Text)=7 > > End Sub > > -- > > HTH, > > Alexander Shirshov, MCSD
> > > Hi, > > > I have a form with a two text boxes: txtUserName and txtPassword, i also > > > have a two command buttons: cmdSubmit and cmdCancel. > > > The cmdSubmit is disabled by default, how can I enable it > programmatically > > > when the two text boxes have been filled with valid data (say for > example > > 7 > > > characters in txtUserName and 8 characters in txtPassword). > > > Thank you, > > > Cube
|
Mon, 08 Dec 2003 19:16:08 GMT |
|
 |
Richar #5 / 10
|
 Simple Question
Quote:
>Hi, >I have a form with a two text boxes: txtUserName and txtPassword, i also >have a two command buttons: cmdSubmit and cmdCancel. >The cmdSubmit is disabled by default, how can I enable it programmatically >when the two text boxes have been filled with valid data (say for example 7 >characters in txtUserName and 8 characters in txtPassword). >Thank you, >Cube
Let's say you have written two routines of your own: Public Function ValidateUserName (str as String) as Boolean Public Function ValidatePassword (str as String) as Boolean Then call code like this in the form with the textboxex and buttons: Private Sub txtUserName_Change() CheckData End Sub Private Sub txtPassword_Change() CheckData End Sub Private Sub CheckData() If ValidateUserName(txtUserName) then If ValidatePassword(txtPassword) then cmdSubmit.Enable = True Else cmdSubmit.Enable = False End IF Else cmdSubmit.Enable = False End If End Sub
|
Mon, 08 Dec 2003 19:17:30 GMT |
|
 |
m.a. #6 / 10
|
 Simple Question
May be one way is to declare two public variables. One like txtUserNameOK and the other txtPasswordOK. In txtUserName_Change if valid, set txtUserNameOK to true, and then check to see if txtPasswordOK is true then enable cmdSubmit, if not leave it alone and got to: In txtPassword_Change if valid, set txtPasswordOK to true, and then check to see if txtUserNameOK is true then enable cmdSubmit, else not. On Form_Load set both variables to false. HTH Regards; mike -- My email address has name of a fruit in it. Please remove the fruit for email replies.
Quote: > Hi, > I have a form with a two text boxes: txtUserName and txtPassword, i also > have a two command buttons: cmdSubmit and cmdCancel. > The cmdSubmit is disabled by default, how can I enable it programmatically > when the two text boxes have been filled with valid data (say for example 7 > characters in txtUserName and 8 characters in txtPassword). > Thank you, > Cube
|
Mon, 08 Dec 2003 19:51:23 GMT |
|
 |
Cube #7 / 10
|
 Simple Question
Thanks guys it worked
Quote:
> >Hi, > >I have a form with a two text boxes: txtUserName and txtPassword, i also > >have a two command buttons: cmdSubmit and cmdCancel. > >The cmdSubmit is disabled by default, how can I enable it programmatically > >when the two text boxes have been filled with valid data (say for example 7 > >characters in txtUserName and 8 characters in txtPassword). > >Thank you, > >Cube > Let's say you have written two routines of your own: > Public Function ValidateUserName (str as String) as Boolean > Public Function ValidatePassword (str as String) as Boolean > Then call code like this in the form with the textboxex and buttons: > Private Sub txtUserName_Change() > CheckData > End Sub > Private Sub txtPassword_Change() > CheckData > End Sub > Private Sub CheckData() > If ValidateUserName(txtUserName) then > If ValidatePassword(txtPassword) then > cmdSubmit.Enable = True > Else > cmdSubmit.Enable = False > End IF > Else > cmdSubmit.Enable = False > End If > End Sub
|
Mon, 08 Dec 2003 19:53:55 GMT |
|
 |
Adrian Edward #8 / 10
|
 Simple Question
You can change If ValidateUserName(txtUserName) then If ValidatePassword(txtPassword) then cmdSubmit.Enable = True Else cmdSubmit.Enable = False End IF Else cmdSubmit.Enable = False End If TO If ValidateUserName(txtUserName) And ValidatePassword(txtPassword) Then cmdSubmit.Enable = True Else cmdSubmit.Enable = False End If Although its a matter of taste. I always think the second one is easier to understand. Adrian
| | >Hi, | > | >I have a form with a two text boxes: txtUserName and txtPassword, i also | >have a two command buttons: cmdSubmit and cmdCancel. | > | >The cmdSubmit is disabled by default, how can I enable it programmatically | >when the two text boxes have been filled with valid data (say for example 7 | >characters in txtUserName and 8 characters in txtPassword). | > | >Thank you, | > | > | >Cube | > | | Let's say you have written two routines of your own: | | Public Function ValidateUserName (str as String) as Boolean | Public Function ValidatePassword (str as String) as Boolean | | | Then call code like this in the form with the textboxex and buttons: | | Private Sub txtUserName_Change() | CheckData | End Sub | | Private Sub txtPassword_Change() | CheckData | End Sub | | Private Sub CheckData() | If ValidateUserName(txtUserName) then | If ValidatePassword(txtPassword) then | cmdSubmit.Enable = True | Else | cmdSubmit.Enable = False | End IF | Else | cmdSubmit.Enable = False | End If | End Sub
|
Mon, 08 Dec 2003 20:21:58 GMT |
|
 |
Adrian Batema #9 / 10
|
 Simple Question
Or even... cmdSubmit.Enable = ValidateUserName(txtUserName) And ValidatePassword(txtPassword) :-) :-)
Quote: > You can change > If ValidateUserName(txtUserName) then > If ValidatePassword(txtPassword) then > cmdSubmit.Enable = True > Else > cmdSubmit.Enable = False > End IF > Else > cmdSubmit.Enable = False > End If > TO > If ValidateUserName(txtUserName) And ValidatePassword(txtPassword) Then > cmdSubmit.Enable = True > Else > cmdSubmit.Enable = False > End If > Although its a matter of taste. I always think the second one is easier to > understand. > Adrian
> | > | >Hi, > | > > | >I have a form with a two text boxes: txtUserName and txtPassword, i also > | >have a two command buttons: cmdSubmit and cmdCancel. > | > > | >The cmdSubmit is disabled by default, how can I enable it > programmatically > | >when the two text boxes have been filled with valid data (say for example > 7 > | >characters in txtUserName and 8 characters in txtPassword). > | > > | >Thank you, > | > > | > > | >Cube > | > > | > | Let's say you have written two routines of your own: > | > | Public Function ValidateUserName (str as String) as Boolean > | Public Function ValidatePassword (str as String) as Boolean > | > | > | Then call code like this in the form with the textboxex and buttons: > | > | Private Sub txtUserName_Change() > | CheckData > | End Sub > | > | Private Sub txtPassword_Change() > | CheckData > | End Sub > | > | Private Sub CheckData() > | If ValidateUserName(txtUserName) then > | If ValidatePassword(txtPassword) then > | cmdSubmit.Enable = True > | Else > | cmdSubmit.Enable = False > | End IF > | Else > | cmdSubmit.Enable = False > | End If > | End Sub
|
Mon, 08 Dec 2003 20:28:03 GMT |
|
 |
CHH #10 / 10
|
 Simple Question
Try using the Validate Event of the txtPassword box ... this will be triggered just before the focus moves from txtPassword --- for example: Private Sub txtPassword_Validate(Cancel As Boolean) If Len(txtPassword) = 8 And <<other conditions>> Then cmdSubmit.Enabled = True Else MsgBox "Password must contain 8 characters." Cancel = True End If End Sub (You could also verify the characters entered if the password is restricted to alphanumeric characters.) Quote: >-----Original Message----- >Hi, >I have a form with a two text boxes: txtUserName and txtPassword, i also >have a two command buttons: cmdSubmit and cmdCancel. >The cmdSubmit is disabled by default, how can I enable it programmatically >when the two text boxes have been filled with valid data (say for example 7 >characters in txtUserName and 8 characters in txtPassword). >Thank you, >Cube >.
|
Tue, 16 Dec 2003 01:09:08 GMT |
|
|