copy and paste

Roland87

Registered User.
Local time
Today, 10:16
Joined
Sep 5, 2012
Messages
26
This one is pretty simple; I have a form with multiple text boxes, and I need a piece of code that immediately copy pastes the content of one textbox into another as the user types into the first one.

Many thanks.
 
In the Control Source of the second text box put the following:

=[NameOfTextBox2]

When you type a value in text box 1 and exit the control, the value entered will immediately appear in Text Box 2.

If you specifically want to do this in code, here is code that you could put in the On Change event of Text Box 1:
Code:
Private Sub txtTextBox1_Change()
Me.txtTextBox2.SetFocus
Me.txtTextBox2.Text = Me.txtTextBox1
Me.txtTextBox1.SetFocus
Me.txtTextBox1.SelStart = Len(Me.txtTextBox1.Text)
Me.txtTextBox1.SelLength = 0
End Sub

Just change the names of txtTextBox1 and txtTextBox2 to the names of your controls.
 
Why would the value need to be placed in a second spot from where you are typing it? That throws up a red flag for me as a potential normalization problem. Perhaps???
 
@ Mr. B thank you, I appreciate it.

@ boblarson, I want to add new records in two tables simultaneously without having to use a subform in my original form. Is there a better way to proceed?
 
This is one of those situations where just answering your question brings up more questions. This brings us back to Bob's observation. Why are you needing to add the same information in another table? Normally you would not need the same information entered into more than one table. You might need to look at the normalization of your database? Please explain a little more exactly what you are doing.
 
Mr. B, it's perfectly allright, my problem's solved, there's no need for that. Thanks again.
 
I think and hope it is better to share frankly when we take advise. The ultimate result shall be fruitful for everyone especially the "New" users many like me would be benefiting from these conversations.

regards.
 

Users who are viewing this thread

Back
Top Bottom