Hi
How do I clean a textbox when the other contains value and vice versa
Example: Two Textbox
Txtbox01 and Txtbox02
When user fill Txtbox01 I must clear Txtbox02, When the user fill Txbox02 Must to clear Txtbox01
:confused:
Printable View
Hi
How do I clean a textbox when the other contains value and vice versa
Example: Two Textbox
Txtbox01 and Txtbox02
When user fill Txtbox01 I must clear Txtbox02, When the user fill Txbox02 Must to clear Txtbox01
:confused:
Possibly useful link:
http://www.vbforums.com/showthread.p...Textbox-Change
@jdc2000, you linked a .Net conversation, but point should be taken -- monitor the Change event.
Tip to Mutley: If you clear a textbox, the change event will also be triggered, if there was anything in the textbox to begin with. So, I'd think that inside your textbox change event, you'd want to test if the change was because you cleared it from your other textbox.
Yeah, this is something I do in one particular place. I've got a form whereby people do physical exams. However, different clients have me design custom forms for their practices. I use the original form as a "master", but then they can call up their "custom" forms over the top of that "master".
And I also have the "master" mirror any changes made to the "custom" forms, although the "master" is disabled while the "custom" form is loaded. To accomplish this, I just monitor the ..._change() event of all the controls on the "custom" form, and shove the changes back into the "master" form.
It does get a bit tricky though. When the "custom" form is initially loaded, I pull all of the initial values out of the "master" form. Therefore, to get it loaded (in the "custom" form's load event), I set a module level mbLoading variable. If that's true, I just immediately exit those ..._change() events. That allows me to get the "custom" form loaded without the code jumping all over the place.
Here's an example of what I do:
Code:
Private Sub cboLeftOrthosis_Change()
If mbLoading Then Exit Sub
frmAddEditPhysicalExams.cboLeftOrthosis.Text = cboLeftOrthosis.Text
End Sub
That's a ComboBox, but same idea.
Good Luck,
Elroy
Huh?
Why not use the KeyUp-Events?
Aircode!
Code:Private Sub Textbox01_KeyUp(whateverargumentsarehere) 'Too lazy to look them up.
If Len(Textbox01)>0 And Len(Textbox02)>0 Then Textbox02.Text=""
End Sub
Private Sub Textbox02_KeyUp(whateverargumentsarehere) 'Too lazy to look them up.
If Len(Textbox01)>0 And Len(Textbox02)>0 Then Textbox01.Text=""
End Sub
Another option would be to check to see if the textbox has focus
Code:Option Explicit
Private Sub Text1_Change()
If Me.ActiveControl Is Text1 Then Text2.Text = vbNullString
End Sub
Private Sub Text2_Change()
If Me.ActiveControl Is Text2 Then Text1.Text = vbNullString
End Sub
Just to reuse...
Code:Option Explicit
Private Sub Text1_Change()
ClearTbx Text1, Text2
End Sub
Private Sub Text2_Change()
ClearTbx Text2, Text1
End Sub
Private Sub ClearTbx(tbx1 As TextBox, tbx2 As TextBox)
If ActiveControl Is tbx1 Then tbx2.Text = ""
End Sub
Just to nitpick... :D
DM's/PGB's Solution sets the Text of the other textbox to empty every time the active Textbox changes, even if it's not necessary (a.k.a the other textbox already being empty)
Code:Private Sub ClearTbx(tbx1 As TextBox, tbx2 As TextBox)
If ActiveControl Is tbx1 and Len(tbx2)>0 Then tbx2.Text = ""
End Sub