基于主表单ID的子表单中的新记录 [英] New record in subform based on ID of main form

查看:55
本文介绍了基于主表单ID的子表单中的新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我想说我是 Access 的初学者,我将感谢我能得到的每一点帮助.

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)

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

但用户必须手动添加父级的 ID,以保持父级和子级记录之间的关系.如何将父记录的 ID 带到当用户单击子表单的添加新记录"按钮时打开的表单?

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?

谢谢!

推荐答案

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

这篇关于基于主表单ID的子表单中的新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆