Anders
Anders

Reputation: 633

New record in subform based on ID of main form

First I want to say that I'm a beginner in Access, and I will appreciate every bit of help I can get.

I have created a form showing records from one of my tables with three subforms. The record and the subforms has a one-to-many relationship. I am now creating buttons for each of the subforms for creating new records in the subforms.

I've managed to make the buttons and used the Macro builder to open the forms in a dialog mode with Add as data mode.

Openform (New recordSub1; Form; ; ; Add; Dialog)

But the users has to manually add the ID of the parent in order to keep the relationship between the parent and the child record. How can I bring the ID of the parent record over to the form which opens when the users click on the "Add new record" button for the subforms?

Thanks!

Upvotes: 2

Views: 2940

Answers (1)

medjahed mohamed
medjahed mohamed

Reputation: 11

With Me.MySubForm.Form.RecordsetClone
     .AddNew
          !data = Your data
          !ID_MySubForm = Me.ID
     .Update
End With

Upvotes: 1

Related Questions