问题
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.
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
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 Link to Document, Check out 'Edit Form Test'
This is a MS Access document, the form has no code attached.
回答1:
I finally fixed this. The biggest problem is to ensure that in the properties: Form> Allow Additions = No
I used the code:
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
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.
回答2:
Have the same issue for a cascade look-up form. I finally just gave the table a dummy first record to overwrite.
来源:https://stackoverflow.com/questions/32595220/ms-access-first-record-in-table-is-overwritten-on-form-close