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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get data into table in subform

Status
Not open for further replies.

adamstuff

Technical User
Sep 13, 2005
41
0
0
US
Hi folks,
You've all been wondeful in helping me and now I have another newbie type question. I have 2 tables that I have related thru the ID field. When I put the data in my form and subform, the ID is not saved into the new record of the second table. It is in the new record on the first table. This of course messes up any ability to see who did what in the second table. I have no idea what kind of additional code I need to put in click event of the SUBMIT button to make sure that the ID is put into the new record is also saved to the second table. Any help would be appreciated to put me on the right track. Am I even making myself clear. I'm not even sure if I have the right join type between tables.
TIA

Heisenberg was probably right.
 
Hi adamstuff,

If I understand you correctly, could you use:

Code:
Private Sub SubmitButton_Click()

Forms!MainForm!Subform.Form!IDField = Forms!MainForm!IDField

'Other code in here

End Sub

Hope I've understood correctly!

Grant
 
You shouldn't have to use code in order to get this to work. This can all be accomplished by defining the proper relationships between the two tables and then creating a form/subform via the form wizard.

I am not sure how your tables are defined, so I will use an example.

tblOrder
OrderID(primary key)
other fields

tblOrderDetails
OrderDetailID (primary key)
OrderID (foreign key to OrderID)

Then in the Relationships window, add both tables and define a relationship between the two tables via the OrderID field. Enable cascade update and deletes along with referential integrity.

Then create a form with the form wizard, first adding fields from the primary table and then fields from the details table. Ensure that the foreign key to the main table is among those fields.

Then everything will be synchronized.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top