我可以用事务包装 Access 表单吗?
我想制作一个表单,本质上是创建发票,但使用一些其他相关数据作为输入或限制; 在向发票添加项目的过程中,我需要减少另一个表中的项目。 由于用户一次会输入多个项目,因此我想在表单加载时发出“START TRANSACTION”,然后在表单更新时发出“COMMIT”。 因此,如果他们取消表单,其他相关表(通过子表单显示)将回滚到以前的值。
I want to make a form the essentially creates an invoice, but using some other related data as inputs or limits; In the process of adding items to the invoice, I need to reduce the items in another table. Since the user will enter several items at a time, I'd like to issue a "START TRANSACTION" when the form loads, and then do a "COMMIT" when the form updates. Thus, if they cancel the form, the other related tables (shown via subforms) would roll back to the previous values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无法使用绑定表单来完成。 您可以使用临时表来存储数据,然后更新主表。 有点拼凑,但我过去就这样做过。
请参阅我网站上的 TempTables.MDB 页面,其中说明了如何使用临时表您的应用程序中的 MDB。
Can't be done using bound forms. You could use temporary tables to store the data and then update the main tables. A bit of a kludge but I've done that in the past.
See the TempTables.MDB page at my website which illustrates how to use a temporary MDB in your app.
是的,可以做到,要以您需要使用以下代码的形式控制交易:
之后就可以使用DBEngine来控制事务了。
它对我有用(我使用 Access 2007)
注意:如果使用表单界面插入新记录,则在引发 Form_AfterInsert 事件时它是可见的,因此您可以在该事件中使用 DbEngine.Rollback 来撤消更改。
Yes it can be done, to take control over the transaction in the form you need use this code:
After that, you can use DBEngine to control the transaction.
It work for me (Im using Access 2007)
Note: If you insert a new record using the form interface it is visible when the Form_AfterInsert event is raised, therefore you can use DbEngine.Rollback in that event to undo the changes.
我发现可以将它放在装订表格上。 您需要在任何父控件的更改事件上分配包含 ID 号的变量所需的一切。 您需要将该 ID 值传输到子表单连接字段中,并在主表单和子表单上执行事务。 这是我如何做到这一点的示例。
I have figured it out its possible to have it on bound forms. Everything you need to assign variable that contain an ID number on change event of any of the parent control. Than you need to transmit that ID value into the subform connected field and perform transaction on both forms the primary and the subform. Here is the example of how I did it.