【译文】当前值与前一条记录的值的比较(相同字段)
时 间:2012-04-13 07:43:45
作 者:周芳 ID:24526 城市:上海
摘 要:在更新后事件,比较字段的原值和字段的新值。
正 文:
原作者:未知 翻译:周芳
【译文】在更新后事件,比较字段的原值和字段的新值。
想知道为什么很难在用户更新字段后找出字段的原值吗?我认为更新前事件可以通过Me.[字段名]获得原值。
这里有一个简单的方法来做到这一点:首先在窗体模块中“Option Compare Database”的代码后面定义一个全局变量。这个例子里,我们定义一个string类型的变量:hold_value.
Option Compare Database
Dim hold_value As String
...
接下来我们在窗体中建立一个“成为当前”事件:
Private Sub Form_Current()
hold_value = Me.icount ’icount是字段名
End Sub
你可能会发现你会得到一个空值的报错,所以你可能想要使用下面的方法来绕开这个小问题:
hold_value = Nz(Me.icount, "") ’把空值转换成空字符串
最后在更新事件后,原值和新值都可供我们使用。
【原文】
Compare original value of field to new value of field in the after update event.
Ever wonder why it is so difficult to figure out what the original value of a form field was after the user updates the field? I thought that the Before Update event would help me do this but using the Me.Fieldname.Oldvalue doesn't give me the old value it gives the new value!
Here is a simple way to do this: First set up a global variable in this form just after the Option Compare Database. In this example we dimension a string variable called hold_value.
Option Compare Database
Dim hold_value As String
...
Next we create an On Current event for the form:
Private Sub Form_Current()
hold_value = Me.icount
End Sub
You may find that you get a null value error so you might want to use the following assignment to get around this little problem:
hold_value = Nz(Me.icount, "")
Finally in the After Update event we have both the new and old values available for us to use.
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access源码示例】一组按...(07.16)
- Access选定Excel区域...(07.02)
- 【Access滑调控件示例】数...(07.01)
- 【Access日期区间段查询示...(06.27)
- 【Access日期区间段查询示...(06.24)
- 【Access日期区间段查询示...(06.21)
- 【Access日期区间段查询示...(06.18)
- 【Access日期时间区间段查...(06.17)
- 【Access Dlookup...(06.15)
![](images/weixin.jpg)
学习心得
最新文章
- Access快速开发平台--编辑修...(07.26)
- SqlServer修改表结构时提示...(07.24)
- Access快速开发平台--通用查...(07.22)
- Access快速开发平台--Acc...(07.18)
- 避免文件已运行时再次打开运行(07.17)
- 【Access源码示例】一组按钮点...(07.16)
- Access通过len函数查询数据...(07.15)
- 一次检查多个字段是否重复(07.15)
- Access报表添加分页符导致强制...(07.13)
- 《生产工序管理系统》基于Acces...(07.11)