我有一些VBA代码设置了TempVar
:
TempVars!ThisQtr = quarter
TempVars!LastQtr = lastQuarter
TempVars!LastYr = lastYear
TempVars!ThisYr = currentYear
大!我知道它确实设置了它,因为我已多次检查。
现在我的问题:
我正在尝试在查询中使用它
DSum("[SumBase]","CompareUnionQuery","[AU] = '" & [AU] & "' AND [GRP_ID] = " & [GRP_ID] & " AND [ACCOUNT] = '" & [ACCOUNT] & "'" & " AND [Fiscal_Year] = " & [TempVars]![ThisYr] & " AND [QTR]= " & [TempVars]![ThisQtr])
当我使用值更改TempVars
时,这会起作用。谁能帮我这个?
我试图在它们周围加一条引号,但这不起作用。
这个表达式确实有效:
DSum("[SumBase]","CompareUnionQuery","[AU] = '" & [AU] & "' AND [GRP_ID] = " & [GRP_ID] & " AND [ACCOUNT] = '" & [ACCOUNT] & "'" & " AND [Fiscal_Year] = 2015 AND [QTR]= '3'")
答案 0 :(得分:1)
比较DSum
表达式的最后几部分......
AND [QTR]= '3'")
AND [QTR]= " & [TempVars]![ThisQtr])
您报告#1有效,#2触发“数据类型不匹配”错误。因此,在TempVar
值之前和之后添加单引号...
AND [QTR]= '" & [TempVars]![ThisQtr] & "'")