PDA

View Full Version : [SOLVED:] Userform: Creating default text in a Textbox from the text entered in another Textbox



ajhez
05-23-2015, 03:40 AM
Hi all,

I'm creating a Word UserForm to populate a document.

In the form there is one section that has 3 TextBoxes. Textbox 1 relates to the first year, Textbox2 the second year and Textbox3 the third year. Quite often the value that will be entered into Textbox 1 will be the same that user will then enter into Textbox 2 and Textbox 3. However this will not always be the case.

What I want to do is - Fill Textbox 2 and Textbox 3 with the text that is inputted into Textbox1 - but so that this can be deleted/retyped with a different text in the event that the user decides the values will be different for 2 and 3.

Any thoughts would be great!

Cheers,
AJHEZ

gmayor
05-23-2015, 04:22 AM
The following code should so the trick



Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.TextBox2.Text = "" Then
Me.TextBox2.Text = Me.TextBox1.Text
End If
If Me.TextBox3.Text = "" Then
Me.TextBox3.Text = Me.TextBox1.Text
End If
End Sub


This will fill textboxes 2 and 3 on exit from textbox1 if they don't already have a value.
You may change 2 and 3 without effecting a change elsewhere.

ajhez
05-23-2015, 07:53 AM
A king amongst men!

Fantastic as always. Thanks so much.

All the best,
AJHEZ