Automatically Copy Data from one text box to another

S

Shiller

Experts,

How do you go about copying data from one text box to another on the
same form. One text box is an unbound text box and the other one is
bound to a table.

I tried using the following in the after update event but it wouldn't
work: Me.textBox1 = Me.textBox2

Thanks
 
G

Guest

First, why are you using the After Update event? Is there a specific reason?
Because in the On Exit event for the "source" textbox, you can place your
code to populate the "destination" textbox, and expect it to work.
 
S

Shiller

First, why are you using the After Update event? Is there a specific reason?
Because in the On Exit event for the "source" textbox, you can place your
code to populate the "destination" textbox, and expect it to work.

Dennis,

I found previous posting by some some experts that recommended to
place the following codes in the after update event of the text box
being used as the source:

Private Sub txtBox1_AfterUpdate()

Me!txtBox2 = Me!txtBox1

End Sub

That was supposed to update txtBox2, but I've been trying all morning
long and it's not working. I also tried the after exit and it didn't
work either.

do you have any idea why?
 
G

Guest

The After Update event is the correct place to do what you are doing.
Your code appears to be correct, so I don't see what the problem is.
Are both text box controls bound or unbound?
 
G

Guest

First of all, "After Update" refers to after a record has been updated, and
has nothing to do with an unbound field. For an unbound field, I'd use On
Exit or On Change. Secondly, your syntax SHOULD WORK if used in the correct
event.

Is the BOUND field your source or destination field? If it's your
destination field, you need to place the source text into it before you
attempt to update/add the record. Have you single-stepped through the code
and hovered over the field(s) (or set them as Watches) to determine the
value(s) in it/them? If not, I suggest you do so.
 
G

Guest

You are correct that the After Update event does not fire for unbound
controls; however, it is more usual to use the Lost Focus event when the
controls are not bound.

You comment on After Update is half correct. If you are talking about the
Form After Update, then yes, if it is a control After Update, it is specific
to the value in the bound control.
 
G

Guest

Thanks for that clarification. I figure that if I hang out here long enough,
SOMEDAY I might have a good understanding of how Access works. (Probably just
in time for MS to retire the product. *sigh* )
 
G

Guest

LOL
hanging out here is a good thing. I have learned most of what I know in
these newsgroups.
 
S

Shiller

LOL
hanging out here is a good thing. I have learned most of what I know in
these newsgroups.

I just found out that the data copies to the new text box if I click
on the source text box then click on the destination text box. I know
I'm getting close to finding a solution.

*the source text box is unbound and the destination is a bound text
box*
 
S

Shiller

I just found out that the data copies to the new text box if I click
on the source text box then click on the destination text box. I know
I'm getting close to finding a solution.

*the source text box is unbound and the destination is a bound text
box*

Thanks guys,

I finally got it work last night. I want to be an expert like you
when I grow up. :)

Shiller,
 
S

Shiller

LOL
hanging out here is a good thing. I have learned most of what I know in
these newsgroups.

Hello,

I used the on current event of the main form to store the data
directly into the field I needed, without needlessly displaying it on
the screen:

Private Sub Form_Current()

Me.DestinationField = Me.txtBox1

End Sub

I was going about doing this the hard way, thanks for your your input
I cracked it. I want to be an expert like you
when I grow up. :)

Y'all my heroes... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top