I have written a VBA code in Access. But, I received syntax error in TRANSFORM statement. I would be grateful if you could help me.
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
RunSQLis for action queries not resultset queries. Additionally, why are you not saving query in database? Stored queries are compiled to best execution plan (i.e., more efficient than VBA string queries called on the fly).