我正在尝试使用Dlookup设置一个变量,该变量引用表中设置的数值。我无法使格式化工作方式与我直接设置值的方式相同。第一个命令工作,第二个命令删除不正确的记录数量,第三个命令提示我“输入参数”
请帮忙。
Sub purge_whse()
Dim purge As Integer
purge = DLookup("Setting_Value", "app_settings", "[Setting_Name]='data_retention'")
DoCmd.RunSQL "DELETE * FROM tbl_whse_cr WHERE DateDiff('m',[INSERT_DTTM],Now()) > 13;"
DoCmd.RunSQL "DELETE * FROM tbl_whse_cr_edi_cnfg WHERE DateDiff('m',[INSERT_DTTM],Now()) > 'purge';"
DoCmd.RunSQL "DELETE * FROM tbl_whse_cr_edi_cnfg WHERE DateDiff('m',[INSERT_DTTM],Now()) > purge;"
答案 0 :(得分:2)
我相信,你想要的是:
DoCmd.RunSQL "DELETE * FROM tbl_whse_cr_edi_cnfg WHERE DateDiff('m',[INSERT_DTTM],Now()) > " & purge & ";"
"吹扫"是一个变量,因此它必须存在于RunSQL字符串之外。