在 Access 2007 表单之间传递数据

发布于 2024-10-31 09:38:35 字数 175 浏览 1 评论 0原文

我的数据库有几个表来分割报告的大量属性。

我创建了一系列表单来使用“下一步”按钮输入数据,该按钮关闭表单并打开下一个表单。

如何在表单之间传递主键?我希望它自动填充,以便用户不必在每个表单上重新输入它。

编辑:每个表单对应一个表。在单击该表单上的“下一步”之前,该表/表单的条目并不存在。

My database has several tables to split up the large number of attributes for a report.

I have created a series of Forms to enter data with a "Next" button which closes the form and opens the next.

How do I pass the primary key between forms? I want it to auto-populate so that the user doesn't have to re-type it on every form.

EDIT: Each form corresponds to a single table. The entry for that table/form doesn't exist until "Next" is clicked on that form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我最亲爱的 2024-11-07 09:38:35

将WhereCondition 与Docmd.OpenForm 结合使用。 (参见OpenForm方法

)如果您的下一个表单名为 frmTwo,主键字段名为 ID,并且当前表单有一个名为 txtID 的控件,其中包含要传递到下一个表单的值:

DoCmd.OpenForm "frmTwo", WhereCondition:="ID = " & Me.txtID

该建议假定 ID 是数字数据类型。如果它是文本,则在构建WhereCondition 时必须用引号将Me.txtID 值引起来。

编辑:我没有清楚地了解你的情况。我现在也不确定,但我怀疑最简单的“无代码”解决方案是使用主窗体和辅助窗体作为子控件。然后,通过设置链接主/子字段属性,您可以自动将主键值传输到各个子表单中的新记录。

如果辅助窗体的数量很大,您可以将它们作为单独的页面包含在主窗体上的选项卡控件中。

Access 可以轻松轻松地完成这种方法,无需额外的 VBA 代码或宏。

Use the WhereCondition with Docmd.OpenForm. (See OpenForm Method)

So if your next form is named frmTwo, the primary key field is named ID, and the current form has a control named txtID which contains the value you want to pass to the next form:

DoCmd.OpenForm "frmTwo", WhereCondition:="ID = " & Me.txtID

That suggestion assumes ID is numeric data type. If it's text, you would have to enclose the Me.txtID value with quotes when building the WhereCondition.

Edit: I didn't understand your situation clearly. Not sure I do now, either, but I suspect the easiest "code-free" solution would be to use a main form with your subsidiary forms as subfrom controls. Then by setting the link Master/Child fields property you can automagically transmit the primary key value to new records in the various subforms.

If the number of subsidiary forms is large, you can include them as separate pages in a tab control on the main form.

That approach is something Access does well and easily, without requiring extra VBA code or macros.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文