问题描述
我有一个基于一张表的数据输入连续表格 (MasterForm).有些记录需要额外的数据,我想在一个单独的弹出表单(后面有另一个表)中输入这些数据.这个弹出表单(SlaveForm)通过触发 DoCmd.OpenForm(vba 指令)的 MasterForm 中的点击事件打开.
I have a continuous form (MasterForm) for data entry based on one table. Some records need additional data, which I want to enter in a separate popup form (which has another table behind). This popup form (SlaveForm) opens by means of a click event in the MasterForm which triggers the DoCmd.OpenForm (vba instruction).
我如何通过 VBA 代码强制"弹出表单(SlaveForm)与 MasterForm 的最后一个当前记录一致",就像我在表单/子表单格式中所做的那样(但这里访问有明确的工具来做到这一点)?
How can I "force" the popup form (SlaveForm) to be "in line" with the last current record of the MasterForm, by VBA code, exactly as I can do in a form/subform format (but here access has explicit tools to do that)?
查看上传的示例https://gofile.io/?c=VvMfiv(我使用的是外部链接,因为我无法在 stackOverflow 中找到如何做到这一点)
See uploaded examplehttps://gofile.io/?c=VvMfiv (I am using an external link, since I was not able to find how I can do that in stackOverflow)
在示例中,让我们假设我们要添加瓦格纳的帕西法尔歌剧.输入名称 Parsifal 后,您选择Have Characters".它将打开 SlaveForm(字符),您要在其中写入Parsifal"和Amfortas".但是,我无法配置 MasterForm 和 SlaveForm 之间的同步.
In the example, let us supose that we want to add Wagner's Parsifal Opera. After entering the name Parsifal you choose "Have Characters". It will open the SlaveForm (characters), where you want to write "Parsifal" and "Amfortas". However, I am not able to configure the synchronization between the MasterForm and the SlaveForm.
有什么建议吗?
推荐答案
经过更多的挖掘,我设法解决了这个问题.从机表单中的 BeforeInsert 事件是关键.查看上传的文件:https://gofile.io/?c=UxRdM8
After some more digging, I manage to solve the problem. The BeforeInsert event in the slave form is the key. See uploaded file: https://gofile.io/?c=UxRdM8
在 MasterForm 中有一个带有主键 (txtIDWork) 的文本框(可以设置为不可见).在 Slave Form 加载后,在 SlaveForm/Table 中插入新寄存器之前,BeforeInsert 事件(SlaveForm 的)确保 MasterForm(当前寄存器的)的主键设置为SlaveForm:
In the MasterForm there is a text box (which can be set to be invisible) with the primary key (txtIDWork). After the Slave Form has been loaded, and before inserting a new register in the SlaveForm/Table, the BeforeInsert event (of the SlaveForm) assures that the primary key of the MasterForm (of the current register) is set to the foreign key of the SlaveForm:
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.txtWorkNumber = Forms.frmMaster.txtIDWork
End Sub
其中txtWorkNumber为写入外键的文本框(可以设置为不可见).
where txtWorkNumber is the text box where the foreign key is written (which can be set to be invisible).
这篇关于将弹出表单与主表单链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!