如何防止F5键在Access中保存来自用户窗体的数据 [英] How to prevent F5 key from saving data from userform in access

查看:220
本文介绍了如何防止F5键在Access中保存来自用户窗体的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MS Access中有一个绑定的表单,我使用一个Submit按钮将数据从表单插入到表中.我的表单中大约有10个字段,即使我只填写1个字段并按F5键,它也只保存了一个字段的数据.如何阻止F5键执行此操作.

I have a bound form in MS Access and I use a submit button to insert the data from form to table. I have around 10 fields in form and even if I fill only 1 field and press the F5 button, it saves the data with just one field. How to stop F5 key from doing this.

编辑-同样,当我关闭包含部分填充数据的表单或意外关闭表单时,或者当我从那里打开设计模式时,它会收集部分填充的数据,然后创建一个条目,以及如何通过以下方式停止用户表单的输入其他方式,并使其仅在单击按钮时创建记录.

Edit - also when I close the form with partially filled data or if it gets closed accidently or when if i open design mode from there, it collects that partially filled data and then creates an entry, how to stop userform making entries via other means and make it only create record on button click.

推荐答案

我认为,您不应停止 F5按钮执行此操作,除了提交按钮之外,您不应停止保存任何其他操作数据.

In my opinion, you should not stop the F5 button from doing this, you should stop anything else than your submit button from saving data.

这可以通过一些VBA代码来实现:

This can be achieved with some VBA code:

在此示例中,保存按钮名为cmdSave

Private saveButtonPressed As Boolean

Private Sub cmdSave_Click()
    saveButtonPressed = True
    DoCmd.RunCommand acCmdSaveRecord
End Sub


Private Sub Form_BeforeInsert(Cancel As Integer)
    If Not saveButtonPressed Then
        'Update through other means
        Cancel = True
    End If
    saveButtonPressed = False
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not saveButtonPressed Then
        'Update through other means
        Cancel = True
    End If
    saveButtonPressed = False
End Sub

这篇关于如何防止F5键在Access中保存来自用户窗体的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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