-
Dec 13th, 2018, 12:35 PM
#1
Thread Starter
Fanatic Member
Two interlinked textboxes
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
-
Dec 13th, 2018, 12:45 PM
#2
Re: Two interlinked textboxes
-
Dec 13th, 2018, 01:48 PM
#3
Re: Two interlinked textboxes
@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.
-
Dec 13th, 2018, 02:13 PM
#4
Re: Two interlinked textboxes
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
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Dec 14th, 2018, 06:13 AM
#5
Re: Two interlinked textboxes
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Dec 14th, 2018, 07:12 AM
#6
Re: Two interlinked textboxes
Originally Posted by Zvoni
Huh?
Why not use the KeyUp-Events?
...
One reason, if you paste text into the textbox, the Key Up event is not triggered.
-
Dec 14th, 2018, 07:41 AM
#7
Re: Two interlinked textboxes
Originally Posted by passel
One reason, if you paste text into the textbox, the Key Up event is not triggered.
Hmm, true.
Code:
Private Sub TextBox1_Change()
If Len(TextBox1) > 0 And Len(TextBox2) > 0 Then TextBox2.Text = ""
End Sub
Private Sub TextBox2_Change()
If Len(TextBox1) > 0 And Len(TextBox2) > 0 Then TextBox1.Text = ""
End Sub
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Dec 14th, 2018, 03:25 PM
#8
Re: Two interlinked textboxes
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
-
Dec 14th, 2018, 05:03 PM
#9
Addicted Member
Re: Two interlinked textboxes
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
-
Dec 15th, 2018, 08:28 AM
#10
Re: Two interlinked textboxes
Just to nitpick...
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|