MS Access-表中的第一条记录在窗体关闭时被覆盖 [英] MS Access - First record in table is overwritten on form close

查看:371
本文介绍了MS Access-表中的第一条记录在窗体关闭时被覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我发现了一些与我的问题很接近的Google搜索结果,但似乎没有人能够帮助他们.

While I've found a few google results that are close to my question, it seems as though no one has been able to help them.

为了简化问题范围,我将表格简化了.

I have a more complicated form that I've simplified in attempt to narrow down the problem.

我有一个编辑库存"表格,可用于编辑资产"表.

I have a Form 'Edit Inventory' that allows for editing of the table 'Assets'.

在编辑库存"表单中,是一个子表单,其中显示了资产表"和几个不同的字段.

Within the form Edit Inventory is a Subform that displays the Asset Table and several different fields.

子窗体上显示的内容基于在组合框"cboRoomSelect"中选择的内容. cboRoomSelect使用其RoomID在资产"表中查找记录

What is displayed on the Subform is based on what is selected in the Combo box 'cboRoomSelect'. cboRoomSelect uses its RoomID to find records in the 'Assets' Table

所有这些都可以正常工作,但是在关闭表单时,第一条记录(出于某种原因是资产表"中的AssetID 5)将"RoomID"更改为cboRoomSelect框中最后选择的RoomID.

All of that works fine, however upon closing the form the very first record (Which for some reason is AssetID 5 in the 'Asset Table') the 'RoomID' is changed to the last selected RoomID in the cboRoomSelect box.

关于解决此问题,我丝毫没有丝毫想法.它仅对于第一条记录才出现,并且仅在关闭记录时才发生.

I haven't the slightest idea on how to fix this. It only occurs for the first record, and only upon closing the record.

结果,记录五在不属于其的房间中不断弹出.

As a result, record five keeps popping up in rooms it doesn't belong.

在此之前,我还遇到了创建重复记录的问题,但是我通过禁用要输入的新记录来解决了这个问题.

Also before this I was having an issue with duplicate records being created, but I solved this by disabling new records to be entered.

此表单上没有任何代码,可以在需要时附加数据库.

I do not have any code in use on this form, and I can attach my database if necessary.

https://drive.google.com/file/d/0BxQbzHNvYazQY3NXWDRZV1lwTjA/view?usp = sharing 链接到文档,签出编辑表单测试"

https://drive.google.com/file/d/0BxQbzHNvYazQY3NXWDRZV1lwTjA/view?usp=sharing Link to Document, Check out 'Edit Form Test'

这是MS Access文档,该表单未附加代码.

This is a MS Access document, the form has no code attached.

推荐答案

我终于解决了这个问题. 最大的问题是确保在属性中: 表格>允许添加=否

I finally fixed this. The biggest problem is to ensure that in the properties: Form> Allow Additions = No

我使用了代码:

Private Sub Form_BeforeUpdated(Cancel as Integer)
If Not (Me.NewRecord) Then
'If not a new record, Undo saving on form
Me.Undo
End If
End Sub

这是因为Access会自动保存所有更改,而不会提示. 上面的代码在Access决定保存之前激活,然后告诉它不要保存.

This is because Access will automatically save any changes without prompting. The above code activates before Access decides to save, then tells it not to.

基本上,代码读取为 在表单关闭时,在更新链接表之前, 如果没有新记录,或者每当关闭该表格/中断自动保存功能. 撤消任何更改/不保存表单更改 结束参数.

Basically the code reads as On form close, before updating linked Table, If there's not a new record, or whenever said form is closed/ Interrupt auto save feature. Undo any changes/ don't save the form changes End arguments.

这篇关于MS Access-表中的第一条记录在窗体关闭时被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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