我正在尝试使用查询使用VBA rowsource运行我的报告。
由于双引号,我在将内置访问查询替换为VBA时遇到问题。
我试过用&替换双引号CHR(34)但不成功。
TRANSFORM Count(History_query.WAS) AS CountOfWAS
SELECT History_query.Datum
FROM History_query
WHERE (((History_query.Datum) Between [Forms]![fr_M-Shiftreport]![Text72] And [Forms]![fr_M-Shiftreport]![Text81]) AND ((History_query.WAS)=[Forms]![fr_M-Shiftreport]![Combo186]))
GROUP BY History_query.Datum
PIVOT History_query.Status In ("erledigt","offen","in Bearbeitung","abgearbeitet / beobachten");
以上查询在Access数据表视图中完美运行,并且还生成了报表图表。
我想在VBA中转换此查询。
答案 0 :(得分:1)
尝试使用单引号:
PIVOT History_query.Status In ('erledigt','offen','in Bearbeitung','abgearbeitet / beobachten');
答案 1 :(得分:0)
我猜你正在遇到逃避vba中引号的问题。你需要加倍双引号才能逃脱它们。如果您可以发布任何错误,那将会有所帮助。以下内容将您的查询结果记录到记录集中。
Sub run()
Dim strSQL As String
Dim db As Database: Set db = CurrentDb
Dim rs As Recordset
strSQL = "TRANSFORM Count(History_query.WAS) AS CountOfWAS " & _
"SELECT History_query.Datum " & _
"FROM History_query " & _
"WHERE (((History_query.Datum) Between [Forms]![fr_M-Shiftreport]![Text72] And [Forms]![fr_M-Shiftreport]![Text81]) " & _
"AND ((History_query.WAS)=[Forms]![fr_M-Shiftreport]![Combo186])) " & _
"GROUP BY History_query.Datum " & _
"PIVOT History_query.Status In (""erledigt"",""offen"",""in Bearbeitung"",""abgearbeitet / beobachten"");"
Set rs = db.OpenRecordset(strSQL)
'do vba stuff...
EXIT_PROC:
Set rs = Nothing
Set db = Nothing
End Sub