Access 宏中的 IF 语句

IF statement in Access Macros

如果父数据 table 中的 ID 键大于子数据 [=26] 中的 ID 键,我正在尝试使用宏实用程序访问 运行 追加查询=],分别命名为Hoover DataHoover Match

我的宏有以下对象:

SetWarnings, No
   If Max([Hoover Data]![ID])>Max([Hoovers Match]![ID])
      OpenQuery, 'Hoovers Match Update'
      CloseWindow, 'Hoovers Match Update'
SetWarnings, Yes

我的查询,Hoovers Match Update 运行很好,在我添加 if 语句之前我的宏也很好——也就是说,尽管 shorthand 写了上面的宏配置正确。

当我 运行 带有 if 语句的宏时,我收到以下错误: Access 找不到您在表达式

中输入的名称 Hoover Data

我运行正在 Win 7(64 位)机器上运行 Access 2013(32 位)

要在外部 tables/queries 中引用聚合,请使用域聚合系列。专为您DMax():

SetWarnings, No
   If DMax("ID", "[Hoover Data]") > DMax("ID","[Hoovers Match]") Then
      OpenQuery
        Query Name 'Hoovers Match Update'
   End If          
SetWarnings, Yes

此外,无需关闭操作查询(append/delete/update)