Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > 综合其它

【译文】如何:提示用户在窗体中编辑数据前对数据的有效性确认

时 间:2013-11-05 07:30:01
作 者:周芳   ID:24526  城市:上海
摘 要:使用BeforeUpdate事件来验证数据的有效性
正 文:

来自:微软  翻译:周芳

【译文】如何:提示用户在窗体中编辑数据前对数据的有效性确认


      您可以使用窗体或者控件的BeforeUpdate事件来执行对进入一个窗体或控件的数据有效性的验证工作。如果窗体或者控件中的数据未通过验证,你可以设置BeforeUpdate事件的取消参数来取消对数据的更新。


      下面的例子可以防止用户对当前记录保存更改一个不包含一个值的单位成本字段值。

 

VBA
Private Sub Form_BeforeUpdate(Cancel As Integer)
 
   ' 检查单位成本字段是否为空白值.
    If IsNull(Me![Unit Cost]) Then
 
       ' 警告用户.
       MsgBox "You must supply a Unit Cost."  
 
      ' 取消更新
      Cancel = True
    End If
End Sub

 

原文:How to: Perform Simple Data Validation Checks When Editing a Record in a Form

 

      You can use the BeforeUpdate event of a form or a control to perform validation checks on data entered into a form or control. If the data in the form or control fails the validation check, you can set the BeforeUpdate event's Cancel argument to True to cancel the update.

     

      The following example prevents the user from saving changes to the current record if the Unit Cost field does not contain a value.

 

VBA
Private Sub Form_BeforeUpdate(Cancel As Integer)
 
   ' Check for a blank value in the Unit Cost field.
    If IsNull(Me![Unit Cost]) Then
 
       ' Alert the user.
       MsgBox "You must supply a Unit Cost."  
 
      ' Cancel the update.
      Cancel = True
    End If
End Sub

 



Access软件网官方交流QQ群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助