New record in subform based on ID of main form

僤鯓⒐⒋嵵緔 提交于 2021-02-10 18:27:05

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/22415770/new-record-in-subform-based-on-id-of-main-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!