如何更改BeforeUpdate中的字段(运行时错误2115) [英] How to change a field in BeforeUpdate (runtime error 2115)

查看:161
本文介绍了如何更改BeforeUpdate中的字段(运行时错误2115)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在BeforeUpdate过程中进行数据验证,但是当我尝试执行此操作时,Access会给我一个运行时错误:

I would like to do data validation in the BeforeUpdate procedure, but Access gives me a runtime error when I try to do this:


运行时错误2115:为此字段设置为BeforeUpdate或ValidationRule属性的函数宏阻止MS Access在字段中保存日期。
Runtime error 2115: The Macro of function set to the BeforeUpdate or ValidationRule property for this field is preventing MS Access from saving the date in the field.



我想要做的一个例子如下:

An example of what I am trying to do is as follows:

展开 | 选择 | Wrap | 行号

推荐答案

设置Cancel = True将不允许更新表单,我不认为这就是你所追求的。根据用户的选择,更改条目或保留记录,然后保存记录。
Setting Cancel = True will not allow the Form to be updated, and I don''t think that this is what you''re after. Depending on the User''s Choice, either change the Entry or leave it along, then Save the Record.
展开 | 选择 | Wrap | 行号


感谢您的回复ADezii,


我误解了取消=真正的设置是如何工作的,谢谢你澄清这一点。如果我将代码附加到表单(如您所有),则代码可以正常工作,但只有在我移动到下一条记录时才会进行验证。有没有办法让它与组合框BeforeUpdate事件一起工作,以便在我点击另一个控件时验证它? (类似于以下内容,根据您的代码改编,仍然会产生运行时错误2115):

Thanks for your reply ADezii,

I misunderstood how Cancel = True setting works, thank you for clarifying that. Your code works if I attach it to a form (as you have it), but then the validation is only done if I move to the next record. Is there some way to make it work with the combo box BeforeUpdate event so that it validates when I click in another control? (something like the following, adapted from your code, which still gives runtime error 2115):

展开 | 选择 | Wrap | 行号


您可能需要使用组合框的LostFocus()事件以使代码有效工作:
You may need to use the LostFocus() Event of the Combo Box in order to have the code work effectively:
展开 | 选择 | Wrap | 行号


这篇关于如何更改BeforeUpdate中的字段(运行时错误2115)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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