【问题标题】:I would like know how to save a record to a table using a form button and open a new form when saving我想知道如何使用表单按钮将记录保存到表中并在保存时打开一个新表单
【发布时间】:2020-07-11 14:41:48
【问题描述】:

我有一个表格“创建类别”,用户可以输入“类别类型”并保存到“类别主”表。如何设置保存按钮以在保存时将记录添加到表中,然后使用创建的新 ID 再次打开表单。

【问题讨论】:

  • 嗨里兹万。有几种方法可以做到这一点。单击保存按钮后,您可以保存新记录并捕获创建的新 ID,然后使用 open form 命令的 where 子句中捕获的 ID 将其他表单打开到新类别。或者,您可以关闭表单,这将自动保存新记录,然后打开新表单并将其过滤到最新记录 - 这假设您的 ID 列是自动编号或递增字段,因此您可以选择最大 ID。这是你想做的吗?
  • 感谢 JennyW 的帮助 :) 你有这方面的 VBA 代码吗?
  • 是的,我正要去上班,所以今天早上晚些时候我会把它寄给你。

标签: vba ms-access


【解决方案1】:

假设Category Master表有CategoryID(整数)和CategoryType(文本)列

Me.dirty = me.dirty false  'this forces the new record to save

'open your other form using the newly created ID in the where clause
DoCmd.OpenForm "YourFormName",,"CategoryID = " & me.CategoryID

'Close the create category form as you have finished with it now
DoCmd.Close acForm, "Create Category"

【讨论】:

    猜你喜欢
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多