我在Access中编写了一个VBA代码。但是,我在TRANSFORM语句中收到语法错误。如果你能帮助我,我将不胜感激。
Sub TransformX1()
Dim dbs As Database
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "TRANSFORM Sum(BAR1.[TON]) AS SumOfTON" _
& "SELECT BAR1.[MABD],Sum(BAR1.[TON]) AS [Total Of TON]" _
& "FROM BAR1" _
& "WHERE (((BAR1.[MABD]) < 1300) And ((BAR1.[MAGH]) < 1300) And ((BAR1.G) = 1))" _
& "GROUP BY BAR1.[MABD]" _
& "PIVOT BAR1.[MAGH]"
DoCmd.RunSQL strSQL
End Sub
答案 0 :(得分:1)
如果你在RunSQL命令之前检查你的strSQL变量,你会发现你缺少一些空格。替换
"TRANSFORM Sum(BAR1.[TON]) AS SumOfTON" _
带
"TRANSFORM Sum(BAR1.[TON]) AS SumOfTON " _
等等。