1

我创建了一个交叉表查询,如下所示

TRANSFORM Nz(Sum([debit]*[GeneralExpenses]),0) AS mOmomeya
SELECT Expenses.sName, Expenses.ArName
FROM (GL INNER JOIN Expenses ON GL.ID = Expenses.glID) INNER JOIN Transactions ON GL.GL = Transactions.GL
GROUP BY Expenses.sName, Expenses.ArName
PIVOT Month([ddate]);

我想要做的是从表单文本输入中向 [dDate] 字段添加一个条件以匹配我输入的日期,但是我在执行此操作时收到错误,如下所示

在此处输入图像描述

知道有什么问题吗?

4

2 回答 2

1

嗯,交叉表查询肯定似乎有些不同。直接的 SELECT 查询...

SELECT expenses.*
FROM expenses
WHERE (((expenses.ddate) Between [Forms]![main]![DateFrom] And [Forms]![main]![DateTo]));

...工作正常,但交叉表查询...

TRANSFORM Sum(expenses.expenses) AS SumOfexpenses
SELECT expenses.onduty
FROM expenses
WHERE (((expenses.ddate) Between [Forms]![main]![DateFrom] And [Forms]![main]![DateTo]))
GROUP BY expenses.onduty
PIVOT Month(ddate);

...失败并显示您引用的错误消息。一种解决方法是在使用之前为查询重建 SQL:

Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs("yourCrosstab")
qdf.SQL = _
        "TRANSFORM Nz(Sum([debit]*[GeneralExpenses]),0) AS mOmomeya " & _
        "SELECT Expenses.sName, Expenses.ArName " & _
        "FROM (GL INNER JOIN Expenses ON GL.ID = Expenses.glID) INNER JOIN Transactions ON GL.GL = Transactions.GL " & _
        "WHERE (((ddate) " & _
            "Between #" & Format(CDate([Forms]![main]![DateFrom]), "yyyy-mm-dd") & "# " & _
            "And #" & Format(CDate([Forms]![main]![DateTo]), "yyyy-mm-dd") & "#)) " & _
        "GROUP BY Expenses.sName, Expenses.ArName " & _
        "PIVOT Month(ddate);"
Set qdf = Nothing
DoCmd.OpenQuery "yourCrosstab"  '' or whatever you want to do with it
于 2013-06-10T19:08:35.757 回答
0

问题是交叉表查询需要每个表单的表单参数。右键单击灰色空间并选择参数。放入表格和数据类型。

于 2014-10-22T22:08:50.090 回答