如何阻止表单从BeforeUpdate事件关闭? [英] How do I stop a form from closing from the BeforeUpdate Event?

查看:125
本文介绍了如何阻止表单从BeforeUpdate事件关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在BeforeUpdate事件中有一些代码,用于检查是否选中了某个复选框。如果不是,我会显示一条消息您是否要取消此交易?使用VbYesNo按钮。我希望能够拥有它,以便如果我单击否,则取消BeforeUpdate事件并停止表单'的关闭事件,以便表单保持打开状态。如果他们单击是,那么我希望运行BeforeUpdate的Cancel = True,然后表单可以关闭。这样做的原因是,如果不检查该字段,我不希望保存记录。我不确定是否设置复选框是否有效,此外,我不知道如何自定义消息,以便普通用户更容易理解这些消息。

I have some code in the forms BeforeUpdate event that checks if a certain checkbox is checked. If it is not, I have a message appear that says "Do you wish to cancel this transaction?" with VbYesNo buttons. I want to be able to have it so that if I click no, the BeforeUpdate event is canceled and the form''s close event stops so that the form remains open. If they click yes, then I want the BeforeUpdate''s Cancel = True to run and then the form can close. The reason for this is that I don''t want the record saving if that field is not checked. I''m not sure if setting the checkbox to be required will work and besides, I don''t know how to customize the messages so that they are more understandable for average users.

推荐答案

在BeforeUpdate事件中,设置在表单的BeforeClose事件中检查的全局变量。
In the BeforeUpdate event, set a global variable that is checked in the BeforeClose event of the form.


当我在做Seth这样的事情时,我添加了一个私有blnAllowClose As布尔在表单顶部的行并将其设置为 True 当且仅当您希望允许表单关闭时。然后 Form_Unload(取消为整数)过程看起来非常像:
When I''m doing such things Seth, I add a Private blnAllowClose As Boolean line at the top of the form and set it to True when, and only when, you want to allow the form to close. The Form_Unload(Cancel As Integer) procedure would then look something very like :
展开 | 选择 | 换行 | 行号


@Rabbit,我曾想过那种方法,但我希望有一种更简单的方法。哦,好吧。


@NeoPa,私人变量怎么样?它不一定是公共变量吗?我是否只是在Option Explicit下面的表单'VBA代码顶部而不是私有子内部声明变量?
@Rabbit, I had thought of that method, but I was hoping that there was an easier way. Oh well.

@NeoPa, How would a Private variable work? Wouldn''t it have to be a public variable? Do I just declare the variable at the top of the form''s VBA code right under the Option Explicit instead of inside a private sub?


这篇关于如何阻止表单从BeforeUpdate事件关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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