MS Access AfterInsert宏更新记录

时间:2018-03-05 19:02:58

标签: ms-access ms-access-data-macro

我对MS Access知之甚少,但我试图创建一个AfterInsert事件。

这里是表格(myTable)上下文 - 该表格将是不同部门的目标列表,并且具有“活动”列。这将允许部门通过创建新记录,将其设置为goal = 1,然后将目标= 1的旧记录更新为Active = False来更改其#1目标。我们需要目标和优先级(目标号码)的运行历史记录。

AutoID  Dept  Goal#  Goal               Active
00001   A     1      My first goal      True
00002   A     2      My second goal     True
00003   A     3      My third goal      True

现在,我想添加一条新记录,因为我们已经改变了目标一。

00004   A     1      My new first goal  True

添加此新记录后应该做的是设置旧目标1 Active = False。

AutoID  Dept  Goal#  Goal               Active
00001   A     1      My first goal      False
00002   A     2      My second goal     True
00003   A     3      My third goal      True
00004   A     1      My new first goal  True

I've been trying to adapt this AfterInsert format

LookupRecord In qryDMTermQuery
 Where Condition = [EmployeeID]=[tblTerminations].[EmployeeID]
 Alias
 EditRecord
    Alias
    Comment Block: Set Active field to False
    SetField
    Name: [qryDMTermQuery].[Active]
    Value: False
 End EditRecord

这是我的改编:

LookupRecord In myTable
 Where Condition = [dept]=[myTable].[dept]
                 AND [Goal#] = [myTable].[Goal#]
                 AND [AutoID] != [myTable].[AutoID]
 Alias
 EditRecord
    Alias
    Comment Block: Set Active field to False
    SetField
    Name: [myTable].[Active]
    Value: False
 End EditRecord

这是否有意义/这是我正在做的事情吗?

1 个答案:

答案 0 :(得分:1)

您快到了。不需要[AutoID] != [myTable].[AutoID],因为生成的新ID显然与现有ID不匹配。或者,您可以使用[AutoID] <> [myTable].[AutoID]

enter image description here