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

【译文】当前值与前一条记录的值的比较(相同字段)

时 间: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交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

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