【译文】如何:提示用户在窗体中编辑数据前对数据的有效性确认
时 间: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群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 统计当月之前(不含当月)的记录...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- 【Access Inputbo...(12.23)
- 【Access Dsum示例】...(12.16)

学习心得
最新文章
- 32位的Access软件转化为64...(04.12)
- 【Access高效办公】如何让vb...(04.11)
- 仓库管理实战课程(10)-入库功能...(04.08)
- Access快速开发平台--Fun...(04.07)
- 仓库管理实战课程(9)-开发往来单...(04.02)
- 仓库管理实战课程(8)-商品信息功...(04.01)
- 仓库管理实战课程(7)-链接表(03.31)
- 仓库管理实战课程(6)-创建查询(03.29)
- 仓库管理实战课程(5)-字段属性(03.27)
- 设备装配出入库管理系统;基于Acc...(03.24)