MS Access:如何禁用表单自动保存并创建保存按钮 [英] MS Access: How to disable Form autosave and create Save button

查看:128
本文介绍了MS Access:如何禁用表单自动保存并创建保存按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解在 MS Access 中以表格形式输入数据会自动更新表格中的字段.但是,如何禁用此功能,而是允许用户单击最后的保存"按钮来更新记录?一直在网上阅读我需要 VBA 等,但我没有经验.

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.

推荐答案

这只能在代码中完成.

您需要设置一个模块级布尔变量来控制保存(自动与手动),并在单击保存按钮时将其值设置为 True.

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

这篇关于MS Access:如何禁用表单自动保存并创建保存按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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