MS Access AfterInsert 宏更新记录

MS Access AfterInsert macro update record

我对 MS Access 的了解非常有限,但我正在尝试创建一个 AfterInsert 事件。

这里是 table (myTable) 上下文 -- table 将是不同部门的目标列表,并且有一个 Active 列。这将允许一个部门通过创建一个新记录来更改它的#1 目标,将其设置为目标 = 1,然后将目标 = 1 的旧记录更新为 Active = False。我们想要 运行 目标和优先级(目标编号)的历史记录。

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

这是否让 sense/is 达到我希望的效果?

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