无法使AfterUpdate宏正常工作 [英] Can't get AfterUpdate Macro to work

查看:65
本文介绍了无法使AfterUpdate宏正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动更新Access 2013中某个字段的属性值,如果该字段中的另一个属性被编辑了.

Hi I would like to automatically update the value of an attribute in a field in Access 2013 if another attribute in that field is edited.

在数据库后端中,我选择了要处理的表,然后单击功能区中的AfterUpdate选项卡,输入这些步骤并保存,但是在更新DATE_OF_DEATH字段时似乎什么也没有发生错误消息生成,所以我什至无法调试它,我也不知道宏是否被触发,或者IF语句是否失败或SetField语句是否失败,我完全处于黑暗的.我非常感谢您提供一些解决此问题的建议.谢谢.

In the database backend I have selected the table I want to work on, and clicked on the AfterUpdate tab in the ribbon I enter these steps and save it, but nothing seems to happen when I update the DATE_OF_DEATH field and there is no error message generated, so I can't even debug the thing, I don't know whether the Macro is even been triggered or not, or if the IF statement is failing or if the SetField statement is failing, I'm totally in the dark. I would really appreciate some advice on fixing this. Thanks.

代码在下面.

If Updated([DATE_OF_DEATH])
    EditRecord
        SetField
            Name OUTCOME
            VALUE = "test"
    End EditRecord
End If

推荐答案

在Access Data宏中刚刚插入或更新的记录是只读的(就像在SQL Server或其他带有触发器的解决方案中一样).您应该在表USysApplicationLog中看到一个错误指示.但是,您可以查找刚刚插入的行,然后对其进行修改.

The just inserted or updated record in an Access Data Macro is read-only (just like in SQL Server or other solutions with triggers). You should see an error indicating that in the table USysApplicationLog. You can, however, lookup the row you've just inserted, and modify it.

您可以为此使用以下宏代码:

You can use the following macro code for that:

SetLocalVar
    Name            NewID
    Expression      =[ID]
If Updated([DATE_OF_DEATH])
    For Each Record In  MyTable
    Where Condition     =[ID]=[NewID]
        EditRecord
            SetField
                Name    OUTCOME
                Value   ="test"
        End EditRecord
End If

这将要求您的记录具有唯一标识符.没有唯一的标识符,我想您将无法实现.您可以尝试使用更改前宏来编辑当前更新的记录,并使用IsInsert仅影响更新,但是不幸的是,这些没有访问Updated函数的权限.

This will require your records to have a unique identifier. Without a unique identifier, I think you can't achieve this. You can try using a Before Change macro to edit the currently updated record and use IsInsert to only affect updates, but unfortunately these don't have access to the Updated function.

这篇关于无法使AfterUpdate宏正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆