2010 访问报告,与输入的搜索条件部分匹配

2010 Access report, partial match from inputted search criteria

我有一个使用以下 SQL 查询的报告:

SELECT AccountPerformanceAllHistory.AccountNumber, 
AccountMaster.AccountName AS Name, AccountCurrentModel.Model,    
AccountPerformanceAllHistory.MarketValue, 
AccountPerformanceAllHistory.Cash, ModelDetailAllHistory.Risk, 
AccountPerformanceAllHistory.QTD, AccountPerformanceAllHistory.YTD, 
AccountPerformanceAllHistory.[1Yr], AccountPerformanceAllHistory.[3Yr], 
AccountMaster.AccountAdvisor AS Advisor, 
AccountPerformanceAllHistory.PerformanceDate, 
AccountPerformanceAllHistory.Ticker
FROM ModelDetailAllHistory INNER JOIN ((AccountMaster INNER JOIN 
AccountPerformanceAllHistory ON AccountMaster.[AccountNumber] = 
AccountPerformanceAllHistory.[AccountNumber]) INNER JOIN 
AccountCurrentModel ON AccountMaster.[AccountNumber] = AccountCurrentModel. 
[AccountNumber]) ON ModelDetailAllHistory.[ModelName] = 
AccountCurrentModel.Model
GROUP BY AccountPerformanceAllHistory.AccountNumber, 
AccountMaster.AccountName, AccountCurrentModel.Model, 
AccountPerformanceAllHistory.MarketValue, 
AccountPerformanceAllHistory.Cash, ModelDetailAllHistory.Risk, 
AccountPerformanceAllHistory.QTD, AccountPerformanceAllHistory.YTD, 
AccountPerformanceAllHistory.[1Yr], AccountPerformanceAllHistory.[3Yr], 
AccountMaster.AccountAdvisor, AccountPerformanceAllHistory.PerformanceDate, 
AccountPerformanceAllHistory.Ticker
ORDER BY ModelDetailAllHistory.Risk, AccountPerformanceAllHistory.[1Yr] 
DESC;

报告是 运行 来自单击按钮:

Private Sub Command3_Click()

Dim StrWhichMonth As String
Dim StrWhichClient As String
Dim CYear, CMonth As Variant
Dim StrSearch As String

StrWhichMonth = InputBox("Enter YYMM you want to report:")
CYear = "20" & Mid(StrWhichMonth, 1, 2)
CMonth = Mid(StrWhichMonth, 3, 2)
StrWhichMonth = DateSerial(CYear, CMonth + 1, 0)

StrWhichClient = InputBox("Enter Client name ('*' for all):")

StrSearch = "AccountPerformanceAllHistory.PerformanceDate = #" & StrWhichMonth _
    & "# AND AccountPerformanceAllHistory.Ticker = " & Chr(34) & "1" & Chr(34) & "" _
    & " AND AccountMaster.AccountName Like " & Chr(34) & StrWhichClient & Chr(34)

StrWhichMonth = "AccountPerformanceAllHistory.PerformanceDate = #" & StrWhichMonth _
    & "# AND AccountPerformanceAllHistory.Ticker = " & Chr(34) & "1" & Chr(34) & ""
DoCmd.SetWarnings False
'    DoCmd.OpenReport "RPTAccountPerformanceAllHistorySummary", acViewReport, , StrWhichMonth
DoCmd.OpenReport "RPTAccountPerformanceAllHistorySummary", acViewReport, , StrSearch
DoCmd.SetWarnings True
End Sub

如您所知,我在按钮点击代码中添加了对 AccountName 的搜索。旧代码工作正常。

新代码,StrSearch 字符串不起作用。当查询为运行时,在两次InputBox提示后提示输入"AccountMaster.AccountName"。我知道这意味着 StrSearch 出了问题,但我不知道出了什么问题。我在网上搜索过,但找不到解决方案。

感谢任何帮助。

TIA

源查询中的字段列表包括这个...

AccountMaster.AccountName AS Name

由于您为该字段设置了别名,查询结果集不包含名为 AccountMaster.AccountName 的字段,因此 Access 假定它必须是一个参数并要求您为其提供一个值。使用别名代替原始字段名称。

改变这个...

& " AND AccountMaster.AccountName Like " & Chr(34) & StrWhichClient & Chr(34)

到这个...

& " AND [Name] Like " & Chr(34) & StrWhichClient & Chr(34)