MS Access: How to disable Form autosave and create Save button

FishFold picture FishFold · Jun 7, 2017 · Viewed 9.5k times · Source

I understand that inputting data in a form in MS Access automatically updates the fields in the table. However, how do I disable this feature and instead allow a user to click a "Save" button at the end to update the records? Have been reading online that I need VBA etc. that I have no experience with.

Answer

Kostas K. picture Kostas K. · Jun 7, 2017

This can only be done in code.

You need to set a module level boolean variable to control saving (auto vs manual) and set its value to True when the save button is clicked.

Private mIsUserUpdate As Boolean 'Flag

'Cancel Auto Save
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not mIsUserUpdate Then Cancel = True
End Sub

'Manual Save
Private Sub YourButtonName_Click()

    '...
    'Do work
    '...

    mIsUserUpdate = True 'OK to save
    DoCmd.RunCommand acCmdSaveRecord
    mIsUserUpdate = False 'Revert
End Sub