Add Record to subform with info from Main form

joltremari

Registered User.
Local time
Today, 12:33
Joined
Jun 4, 2001
Messages
24
I have a Main form in which lots of info is keyed into, there is a subform that we use as history records. The history records only needs info from a few fields on the main form. What I want to do is make a command button that will, after keying in the info to the main form, click and it will add a new record to the subform and send only the info it requires to it.
What's the best way to accomplish this?
I hope this is clear enough to understand what I trying to do.

Thanks for any input...

JO
 
I am sorry, but why do you want to put info that is already on your main form into your subform. Usually, you do not want to repeat data that are already stored. Have you linked your subform and main form?

Reply why you want to do this and we'll se if it makes sense to put some code in your DB.

Pookatech
 
This database keeps records of Transformers (like on a power distribution pole) and we are required to keep track of everytime a transformer is moved. So the main form keeps a lot of info about the transformer that different people need to access, but each time that transformer is moved we have to update several fields of data on that main form and add that data to the "History" so we know where it used to be.
I hope this is making sense.
So when I key in a transformer and click my 'History' button I would like it to send the required info to the history subform, then the next time it is moved and I key in the knew info and click the button it will add that info to the history subform abd so-on.. I have a relationship between the tables by serial number of the transformer.

I hope this made sense.

JO
 
Ok now I see the reason for the data to be dupicated.

The best way I know how to do this is to attach the following code, which by clicking the button named "command3" on the parent form "frmOwners" creates a new record on the subform "frmPets" and copies the "ownerName" from the main form to the subform.


Private Sub Command3_Click()

Forms![frmOwners]![frmPets].SetFocus 'sets the focus to the subform

DoCmd.GoToRecord acActiveDataObject, , acNewRec 'creates a new record on the subform

Forms![frmOwners]![frmPets]![OwnerName] = Forms![frmOwners]![OwnerName] 'copies the information from the main form to the subform

End Sub

You will of course need to repeat the last command for each field you want to copy information for. One last thing, this is access 97 code and if you are using Access 2000 or 2002 you may need to reference the subform and controls differently. There are a lot of post on the forms forum about referencing controls and subforms, so look there if you have trouble.

Good luck,
Pookatech
 
Yes that is it!
I am using 2002 but it worked fine.
That is exactly what I've been trying to do. I hit all around it but never quite got it.

Thanks-a-gig

JO
 

Users who are viewing this thread

Back
Top Bottom