禁止在窗体关闭时将字段留空 [英] Preventing fields from being left blank when form closed

查看:69
本文介绍了禁止在窗体关闭时将字段留空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找可能非常简单的事情。当我关闭表单时,如果某些字段留空,那么我想要弹出一条消息告诉用户这些字段是必需的,然后他们可以返回并填写它们。


下面是代码(我发现并略微修改),当用于检查ONE字段时它起作用,但是当我为要检查的附加字段添加代码时,它返回错误(运行时错误2450) - Access can'找不到宏表达式或Visual Basic代码中引用的''Frm_Case''形式

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

解决方案

对于第二次测试,您的语法不正确,即vbOKOnly不是有效的MsgBox结果,并且您无法处理And条件:

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号


我有点困惑 - 如果vbOKOnly不是有效的MsgBox结果而且无法添加到条件中,为什么它在第一次测试中有效而不是第二个?


根据你的建议将所有这些代码移到Form'的BeforeUpdate()事件会更明智吗?


<块引用>


我有点困惑 - 如果vbOKOnly不是一个有效的MsgBox结果并且无法解决这个问题,为什么它在第一个测试中起作用而不是第二个测试?



vbOKOnly是一个MsgBox''Argument''并且计算结果为0,而vbOK是一个MsgBox结果并且评估为1.你正在做的是评估返回结果Msgbox函数并测试它是否为0(vbOKOnly),它总是计算为False,因为0不是有效的Msgbox结果。然后,您将使用And条件来评估SetFocus方法的结果,这对我来说毫无意义。我可以从错误的角度看这个,看看其他会员要说的话。


将所有这些代码移到根据您的建议,Form'的BeforeUpdate()事件?



我是这么认为的,但你可能必须将Cancel Argument设置为true才能否定表格的更新。


I am struggling with something that is probably quite simple. When I close a form, if certain fields are left empty then I want a message to pop up to tell the user these fields are required and then they can go back and fill them in.

Below is the code (which I found and modified slightly) and it works when used to check ONE field but when I added code for an additional field to be checked, it returns an error (run-time error 2450) - Access can''t find the form ''Frm_Case'' referred to in a macro expression or Visual Basic code

Expand|Select|Wrap|Line Numbers

解决方案

For the 2nd Test, your syntax is incorrect, namely vbOKOnly is not a valid MsgBox Result, and you cannot tack on the And condition:

Expand|Select|Wrap|Line Numbers


I''m a little confused - if vbOKOnly is not a valid MsgBox Result and And cannot be tacked onto the condition, why does it work in the first test and not the second?

Would it be wiser to move all of this code to the Form''s BeforeUpdate() Event as per your suggestion?


I''m a little confused - if vbOKOnly is not a valid MsgBox Result and And cannot be tacked onto the condition, why does it work in the first test and not the second?

vbOKOnly is a MsgBox ''Argument'' and evaluates to 0 while vbOK is a MsgBox Result and evaluates to 1. What you are doing is evaluating the Return results of the Msgbox Function and testing to see if it = 0 (vbOKOnly) which will always evaluate to False since 0 is not a valid Msgbox Result. You then tack on an And condition to evaluate the Result of the SetFocus Method which makes no sense to me. I could be looking at this from the wrong angle, see what other Members have to say.

Would it be wiser to move all of this code to the Form''s BeforeUpdate() Event as per your suggestion?

I think so, but you may have to set the Cancel Argument to true in order to negate the Update of the Form.


这篇关于禁止在窗体关闭时将字段留空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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