How can I SWITCH the contents of 2 textboxes by clicking on a command button?
I tried to solve it this way :

Private Sub Command1_Click()
Text1.Text = Text2.Text
Text2.Text = Text1.Text
End Sub

But it didn't work out and it only changes the content of text1
Thanks in advance :)

Edited 7 Years Ago by Nick Evan: Added code-tags

That's because by the time Text2.Text = Text1.Text executes, Text1.Text has already been changed. Try:

Dim Txt as String
Txt = Text1.Text
Text1.Text = Text2.Text
Text2.Text = Txt

You need an extra variable. After you say: Text1.Text = Text2.Text text1 and text2 will both have the same text (from text2), so this Text2.Text = Text1.Text is useless.

Use something like:

tmp = Text1.Text
Text1.Text = Text2.Text
Text2.Text = tmp

Crossposted with scbwv

Edited 7 Years Ago by Nick Evan: n/a

Actually, you don't need to declare a variable. You can use the tag property for something like this...

Option Explicit

Private Sub Command1_Click()
Text1.Tag = Text2.Text
Text2.Text = Text1.Text
Text1.Text = Text1.Tag
End Sub

Read up on it...

Good Luck

This question has already been answered. Start a new discussion instead.