VBA- TRANSFORM语句中的语法错误

时间:2016-12-20 11:56:48

标签: excel vba excel-vba

我在VBA中有错误,此查询正常作为交叉表运行但是当我尝试切换VBA时,在TRANSFORM语句中抛出语法错误有人可以帮助我吗?谢谢。

     "TRANSFORM Str(Count([Prijava].[id]))AS O, Str(Count([Prijava].[datumSmrti])) AS U" & _
     "SELECT MKB10.id, IIf([pol].[id]=1,'M','Ž') AS pol, MKB10.NazivLatinski" & _
     "FROM Pol INNER JOIN ((Opstina INNER JOIN Pacijent ON Opstina.id = Pacijent.opstinaID) INNER JOIN (MKB10 INNER JOIN Prijava ON MKB10.id = Prijava.mkb10ID) ON Pacijent.id = Prijava.pacijentID) ON Pol.id = Pacijent.polID" & _
     "GROUP BY MKB10.id, IIf([pol].[id]=1,'M','Ž'), MKB10.NazivLatinski" & _
     "ORDER BY MKB10.id" & _
     "PIVOT starosnoDoba2([starost]) In ('<1','1','2','3','4','5','6','7-9','10-14','15-19','20-29','30-39','40-49','50-59','60-69','70>')"

2 个答案:

答案 0 :(得分:2)

 "TRANSFORM Str(Count([Prijava].[id]))AS O, Str(Count([Prijava].[datumSmrti])) AS U " & _
     "SELECT MKB10.id, IIf([pol].[id]=1,'M','Ž') AS pol, MKB10.NazivLatinski " & _
     "FROM Pol INNER JOIN ((Opstina INNER JOIN Pacijent ON Opstina.id = Pacijent.opstinaID) INNER JOIN (MKB10 INNER JOIN Prijava ON MKB10.id = Prijava.mkb10ID) ON Pacijent.id = Prijava.pacijentID) ON Pol.id = Pacijent.polID " & _
     "GROUP BY MKB10.id, IIf([pol].[id]=1,'M','Ž'), MKB10.NazivLatinski " & _
     "ORDER BY MKB10.id " & _
     "PIVOT starosnoDoba2([starost]) In ('<1','1','2','3','4','5','6','7-9','10-14','15-19','20-29','30-39','40-49','50-59','60-69','70>') "

加入字符串时需要空格,否则文字会一起运行......你们正在阅读"TRANSFORM..... AS USELECT..."

答案 1 :(得分:1)

我发现答案是愚蠢的,一切都很好,当然它有效,但有些事情需要纠正,哪里有逗号应该站着&amp; &#34;&#34; &#34;&#34; &安培;并且因为它是在一个字符串之后继续&amp; _之前应该像pollID那样站立空间&#34; 所以,看起来像这个`

"TRANSFORM Str(Count([Prijava].[id]))&"" ""& Str(Count([Prijava].[datumSmrti])) " & _
"SELECT MKB10.id &"" ""& IIf([pol].[id]=1,'M','Ž') &"" ""& MKB10.NazivLatinski " & _
"FROM Pol INNER JOIN ((Opstina INNER JOIN Pacijent ON Opstina.id = Pacijent.opstinaID) INNER JOIN (MKB10 INNER JOIN Prijava ON MKB10.id = Prijava.mkb10ID) ON Pacijent.id = Prijava.pacijentID) ON Pol.id = Pacijent.polID " & _
"GROUP BY MKB10.id, IIf([pol].[id]=1,'M','Ž'), MKB10.NazivLatinski " & _
"ORDER BY MKB10.id " & _
"PIVOT starosnoDoba2([starost]) In ('<1','1','2','3','4','5','6','7-9','10-14','15-19','20-29','30-39','40-49','50-59','60-69','70>') "