我正在使用Access 2010,并通过子窗体上的各种控件从用户提取信息来动态创建字符串过滤器。然后我以两种方式之一使用过滤器:
我在数据表视图中设置了另一个子表单的记录源
Forms![frmCentral]![TrainingEventsSubform].Form.RecordSource =
gstrTrainingEventsFormFilter
或者我将它用作openreport的查询参数
DoCmd.OpenReport "rptTrainingEvents", acViewPreview, gstrTrainingEventsFormFilter
我不明白为什么,但查询字符串在设置记录源时工作正常,但完全相同的字符串将导致在发出openreport命令时出现“输入参数值”框。此外,如果我将其粘贴到报告的recordsource参数中,查询将完美运行。
例如,这是一个构建的字符串:
SELECT TrainingEvents.StartDate, TrainingEvents.EndDate, ClassList.ClassNumber, [Users].[FirstName] & ' ' & [Users].[LastName] AS Trainer, TrainingLocations.TrainingLocationName, EventVenues.EventVenueName, TrainingEventStatus.TrainingEventStatus, TrainingEvents.TrainingEventID
FROM Users INNER JOIN (TrainingLocations INNER JOIN (TrainingEventStatus INNER JOIN (EventVenues INNER JOIN (ClassList INNER JOIN TrainingEvents ON ClassList.ClassID = TrainingEvents.ClassID) ON EventVenues.EventVenueID = TrainingEvents.EventVenueID) ON TrainingEventStatus.TrainingEventStatusID = TrainingEvents.EventStatusID) ON TrainingLocations.TrainingLocationID = TrainingEvents.TrainingLocationID) ON Users.UserID = TrainingEvents.TrainerID
WHERE (TrainingEvents.StartDate >= #1/1/2014#) AND (TrainingEvents.EndDate <= #12/31/2014#) AND (Users.UserID = 10)
ORDER BY TrainingEvents.StartDate;
将显示“输入参数值”框,其中包含Users.UserID。
这显然与用户ID有关,但对于我的生活,我无法理解是什么!
有什么建议吗?