【译文】如何:提示用户在窗体中编辑数据前对数据的有效性确认-周芳
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


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

发表时间:2013/11/5 7:30:01 评论(0) 浏览(5140)  评论 | 加入收藏 | 复制
   
摘 要:使用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群(群号:198465573)
 
 相关文章
【译文】如何为一个组合框或列表框添加全选按钮  【周芳  2013/8/27】
【译文】如何从一个表中指定一个控件的值  【周芳  2013/9/3】
【译文】如果主窗体不包含记录,如何隐藏它的子窗体  【周芳  2013/9/10】
【译文】如何判断当前的记录在窗体里是否是一个新记录  【周芳  2013/10/18】
【译文】如何在保存一个记录前提示用户  【周芳  2013/10/29】
常见问答
技术分类
相关资源
文章搜索
关于作者

周芳

文章分类

文章存档

友情链接