Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy data from access field to another field in same form

Status
Not open for further replies.

nogero

Programmer
Mar 1, 2007
43
US
I have a form in MS Access connected to one table. In the form I want to use a command button so when the user clicks it , it will copy the contents from one text box to another. I have tried to use the Me!txtname1 = Me!txtname2 but it doesn't seem to work.

Is there a good way to use a command button to copy data in a text box to another text box on the same form? Even if the data is not yet saved to the table. I know storing similar data in a table is not recommend, but in this case it will need to be done. Thank you.
 
This works fine for me. What happens? Do you get an error, nothing happens?
 
The on click code for my command button is below. What happens is when I click on the button in the form the data in txtsecholderln disappers and then nothing gets added to txtsecholderln. I must be doing something wrong. Any help is appreciated.


Private Sub Copy_Data_Click()
On Error GoTo Err_Copy_Data_Click

Me!txtsecholderln = Me!txtsecholderfn

Exit_Copy_Data_Click:
Exit Sub

Err_Copy_Data_Click:
MsgBox Err.Description
Resume Exit_Copy_Data_Click

End Sub
 
Substitute . for !
Code:
Private Sub Copy_Data_Click()
On Error GoTo Err_Copy_Data_Click

    Me[b].[/b]txtsecholderln = Me[b].[/b]txtsecholderfn

Exit_Copy_Data_Click:
    Exit Sub

Err_Copy_Data_Click:
    MsgBox Err.Description
    Resume Exit_Copy_Data_Click
    
End Sub

HTH
Lightning
 
It has to be asked; Why does it have to be saved in two places?

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
I disagree with Lightning, either bang or dot notation should work. So assume you have field1 and field2 with associated text boxes txt1 and txt2. Then any of the following should work

me.txt2 = me.txt1
me!txt2 = me!txt1
me.fld2 = me.fld1
me!fld2 = me!fld2

Why these notations all work is interesting discussion, and leads to arguments of which is better. I personally would use the third case.

My guess is that you have your fields names backwards, so you are setting the filled in textbox to the value of the blank text box and not setting the blank textbox to the value of the filled in textbox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top