Set a textbox in a form the same as another

I have a quick problem. I need a macro or code that will set a textbox in form A the same as Form B

so something like this

Set FormaA.textbox1 = FormB.textbox2

thanks in advance
Who is Participating?
mbizupConnect With a Mentor Commented:
You can also use the Me prefix if the code is on the same form as one of the boxes

Me.text = forms!formb.text2
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
you can do this
Forms!FormaA.textbox1 = Forms!FormB.textbox2

Forms!FormaA!textbox1 = Forms!FormB!textbox2
damixaAuthor Commented:
I need to have a button that updates textbox1 = textbox2

once I am on form containing textbox2, I need to be able to change this if I need to without changing textbox1

so just a Set button that updates the values
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

damixaAuthor Commented:
So do I do this as a macro? what kind of action do I choose?
Rey Obrero (Capricorn1)Commented:
<I need to have a button that updates textbox1 = textbox2>

place the codes in the click event of the button

private sub btnName_Click()

Forms!FormaA.textbox1 = Forms!FormB.textbox2

end sub
Jeffrey CoachmanMIS LiasonCommented:
And just to be clear, ...
Why is this needed?
How is the data in the two form related?

I only ask because this is a very rare request, so perhaps there may be a alternate approach to doing this...

I am just curious really

<So do I do this as a macro? what kind of action do I choose?>

What we are describing is VBA (Visual Basic for Applications) not macros, which is how the regulars here generally respond -  most of us prefer VBA over macros for a variety of reasons.

The way you would enter this type of code is - for a command button, in design view -  right click the button, then select "Build Event", then "Code Builder" and enter the code in between the Sub and End Sub lines when the VBA editor opens.

This also can be done with macros if you want ... the Action you are looking for is SetProperty, and you would set the Value property.  The resulting macro might look something like this:

But I'd suggest VBA over macros in the long run, for easier debugging, greater versatility, etc...
Helen FeddemaCommented:
When I first read your question, I thought you wanted to create another textbox the same as the first, but I think you are referring to the value in the textbox, which is quite a different matter.

If Form B is to have the same value in a textbox as in a textbox on Form A, often their data sources are related.  Is that so?  Is Form B opened from Form A?  In that case, you could set the value of the textbox on Form B from a button that opens Form B, or Form B's Load event.  We need more information here.  You may not need to set the value of the textbox on Form B at all, if the relationships are set up correctly.
damixaAuthor Commented:
Thanks Guys!
All Courses

From novice to tech pro — start learning today.