Code to copy fields?

JustMaybe

Registered User.
Local time
Today, 13:52
Joined
Oct 18, 2002
Messages
134
I have a button which allows me to open another form in my database, this forms are not connected. However when this form button is activated i would also like some fields from this table A to be copied into the table B and be displayed on the newly opened form. I'm getting confused with my code...could anyone help?

I only know how to do thhis with forms connected by foreign keys!!

Thanks in advance S
 
Not sure exactly what you mean? Let me see if I have this right. You have two forms, Form A is based on Table A and Form B is based on Table B.
Now you can open Form B from Form A.
Now here's where I get a bit lost so I have two questions.

1. Do you want to copy information entered into some of the fields in Form A to some other fields in Form B? Then when you save the information in Form B it will be saved to the table, Table B?

2. If so, when you open Form B does Form A close or does it remain open in the background?

If Q1 is what you want to do then it's pretty straight forward, but I need to know the answer to Q2 first as there are two very different sols depending on what you do with Form A after you open Form B.

Of course I could be totally off the mark, too. Let me know!

Liam
 
Sorry Liam...am not great at describing myself...

1. Yes i want to copy the information !

2. Form A will remain open in the background!!

(I want the fields from form (table) A to be copied if the user accesses Form B from form A - and formA will be still open)

However these fields need to be entered manually if the user opens the form independantly!)

Thank you soo much in advance if you can help.

Sarah
 
Right!

Lets say you have a Form called "FormA" and a Form called "FormB". Now lets also assume you have a field in "FormA" called "Name" and you have a field in "FormB" called "UserName". so here goes; in the onClick event of the button you use to open FormB put the following:

Code:
Dim stDocName As String
'The name of the form to be opened i.e. "FormB"
stDocName = "FormB"
'Open the this form, FormB
DoCmd.OpenForm stDocName
'sets the value of the field, UserName, in FormB to the value of the field, Name, in FormA
[Forms]![FormB]![UserName] = [Forms]![FormA]![Name]

Alternatively you could also use the following line of code instead of the last line I have used here:

[Forms]![FormB]![UserName] = Me![Name]

'Me' simply is shorthand and means the object (in this case a form) which is running this code.

Just repeat this last line of code as many times as you have fields to fill in, obviously changing the name of the field for each line to the appropriate field name.

Hope this solves your problem and if it doesn't let me know.

Liam
 
Thank you sooo much Liam. The code worked like a dream!!!
...you solved a big problem thats been bugging me for ages..cheers :D

Sarah
 

Users who are viewing this thread

Back
Top Bottom