Access 2007 Error 3071 -report using parameters

时间:2015-12-07 17:23:11

标签: sql ms-access

我在MS Access 2007中有一个查询,它从两个不同的表中提取数据并在报表中显示。用户单击主窗体上的按钮后会发生这种情况,这会打开一个日期字段参数表单,用户可以在其中选择两个日期。从那里查询使用用户提供的两个日期运行,或者日期是伪造的'如果没有选择填写日期。我收到运行时错误3071,此表达式输入错误,或者它太复杂而无法评估,我不确定原因。

我在另一个数据库中运行一个类似的查询,它执行得非常好,所以我不知所措。

查询在下面,

(SELECT 
[Group Name], 
tbGroups AS [Group Number],
Analyst, 
[Account Manager], 
NULL AS [SER Number], 
[Received Date] AS [Corporate Recevied],
DateValue(Created) AS [Sales Submitted], 
tbBAAcceptedDate AS [BA Accepted], 
NULL AS [Submitted to MDSS], 
NULL AS [Completed],
NULL AS [Cancelled],
DateDiff("d",[Received Date], IIf([Forms]![frmReportDateFilter].[tbToDate] = '01/01/2116', Date(), CDate([Forms]![frmReportDateFilter].[tbToDate]))) AS [Aging Days Count],
LocalID AS [ID Number]
FROM ChangeRequest
WHERE DateValue([Created]) BETWEEN CDate([Forms]![frmReportDateFilter].[tbFromDate]) AND CDate([Forms]![frmReportDateFilter].[tbToDate]))
UNION ALL (SELECT 
tbGroupProgramProductName AS [Group Name], 
tbGroups AS [Group Number], 
cboAnalyst AS Analyst, 
tbAccountManager AS [Account Manager], 
tbSERNumber AS [SER Number], 
tbCorpReceivedDate AS [Corporate Recevied],
tbBAReceivedDate AS [Sales Submitted],
IIf([tbBAAcceptedDate] > CDate([Forms]![frmReportDateFilter].[tbToDate]), NULL, [tbBAAcceptedDate]) AS [BA Accepted],
IIf([tbSubmittedToMDSS] > CDate([Forms]![frmReportDateFilter].[tbToDate]), NULL, [tbSubmittedToMDSS]) AS [Submitted to MDSS],
DateValue(tbCompleteDate) AS [Completed],
DateValue(tbCancelDate) AS [Cancelled],
DateDiff("d",tbCorpReceivedDate, IIf([Forms]![frmReportDateFilter].[tbToDate] = '01/01/2116', Date(), CDate([Forms]![frmReportDateFilter].[tbToDate]))) AS [Aging Days Count],
LocalID AS [ID Number]
FROM tblDD
WHERE DateValue([tbBAReceivedDate]) BETWEEN CDate([Forms]![frmReportDateFilter].[tbFromDate]) AND CDate([Forms]![frmReportDateFilter].[tbToDate]))
ORDER BY [Group Name];

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

将控件指定为Date。像这样没有CDate的东西 - 没有外括号:

PARAMETERS 
[Forms]![frmReportDateFilter].[tbFromDate] Date,
[Forms]![frmReportDateFilter].[tbToDate] Date;
SELECT 
[Group Name], 
tbGroups AS [Group Number],
Analyst, 
[Account Manager], 
NULL AS [SER Number], 
[Received Date] AS [Corporate Recevied],
DateValue(Created) AS [Sales Submitted], 
tbBAAcceptedDate AS [BA Accepted], 
NULL AS [Submitted to MDSS], 
NULL AS [Completed],
NULL AS [Cancelled],
DateDiff("d",[Received Date], IIf([Forms]![frmReportDateFilter].[tbToDate] = #01/01/2116#, Date(), [Forms]![frmReportDateFilter].[tbToDate])) AS [Aging Days Count],
LocalID AS [ID Number]
FROM ChangeRequest
WHERE DateValue([Created]) BETWEEN [Forms]![frmReportDateFilter].[tbFromDate] AND [Forms]![frmReportDateFilter].[tbToDate]
UNION ALL 
SELECT 
tbGroupProgramProductName AS [Group Name], 
tbGroups AS [Group Number], 
cboAnalyst AS Analyst, 
tbAccountManager AS [Account Manager], 
tbSERNumber AS [SER Number], 
tbCorpReceivedDate AS [Corporate Recevied],
tbBAReceivedDate AS [Sales Submitted],
IIf([tbBAAcceptedDate] > [Forms]![frmReportDateFilter].[tbToDate], NULL, [tbBAAcceptedDate]) AS [BA Accepted],
IIf([tbSubmittedToMDSS] > [Forms]![frmReportDateFilter].[tbToDate], NULL, [tbSubmittedToMDSS]) AS [Submitted to MDSS],
DateValue(tbCompleteDate) AS [Completed],
DateValue(tbCancelDate) AS [Cancelled],
DateDiff("d",tbCorpReceivedDate, IIf([Forms]![frmReportDateFilter].[tbToDate] = #01/01/2116#, Date(), [Forms]![frmReportDateFilter].[tbToDate])) AS [Aging Days Count],
LocalID AS [ID Number]
FROM tblDD
WHERE DateValue([tbBAReceivedDate]) BETWEEN [Forms]![frmReportDateFilter].[tbFromDate] AND [Forms]![frmReportDateFilter].[tbToDate]
ORDER BY [Group Name];