R
Renate
I have a SQL statement which I would like to rebuild from within VBA to
use different fieldnames and the content of variables.
This is the SQL:
'TRANSFORM Nz(Count([ReportNo]),0) AS TotalNumber
'SELECT Year([DateField]) AS Year
'FROM Table
'GROUP BY Year([DateField])
'PIVOT Month([DateField]) In
('1','2','3','4','5','6','7','8','9','10','11','12');
The name of the table (Table) and of the Datefield (Datefield) should
be populated with the content of variables.
This is my VBA code so far:
sSQL = "TRANSFORM Nz(Count([ReportNo]),0) AS TotalNumber"
sSQL = sSQL & " ,SELECT Year([" & sDateField & "]) AS Year"
sSQL = sSQL & " ,FROM " & sTabel
sSQL = sSQL & " ,GROUP BY Year([" & sDateField & "])"
sSQL = sSQL & " ,PIVOT Month([" & sDateField & "]) In (" & Chr(34) &
"1" & Chr(34) & ", " & Chr(34) & "2" & Chr(34) & ", " & Chr(34) & "3" &
Chr(34) & ", " & Chr(34) & "4 ," & Chr(34) & "5" & Chr(34) & ", " &
Chr(34) & "6" & Chr(34) & ", " & Chr(34) & "7" & Chr(34) & ", " &
Chr(34) & "8, " & Chr(34) & "9" & Chr(34) & ", " & Chr(34) & "10" &
Chr(34) & ", " & Chr(34) & "11" & Chr(34) & ", " & Chr(34) & "12)"
The variables sTabel and sDateField contain the names of table and
datefield I want to use.
I can't get this ssql to run. Can somebody help me please?
use different fieldnames and the content of variables.
This is the SQL:
'TRANSFORM Nz(Count([ReportNo]),0) AS TotalNumber
'SELECT Year([DateField]) AS Year
'FROM Table
'GROUP BY Year([DateField])
'PIVOT Month([DateField]) In
('1','2','3','4','5','6','7','8','9','10','11','12');
The name of the table (Table) and of the Datefield (Datefield) should
be populated with the content of variables.
This is my VBA code so far:
sSQL = "TRANSFORM Nz(Count([ReportNo]),0) AS TotalNumber"
sSQL = sSQL & " ,SELECT Year([" & sDateField & "]) AS Year"
sSQL = sSQL & " ,FROM " & sTabel
sSQL = sSQL & " ,GROUP BY Year([" & sDateField & "])"
sSQL = sSQL & " ,PIVOT Month([" & sDateField & "]) In (" & Chr(34) &
"1" & Chr(34) & ", " & Chr(34) & "2" & Chr(34) & ", " & Chr(34) & "3" &
Chr(34) & ", " & Chr(34) & "4 ," & Chr(34) & "5" & Chr(34) & ", " &
Chr(34) & "6" & Chr(34) & ", " & Chr(34) & "7" & Chr(34) & ", " &
Chr(34) & "8, " & Chr(34) & "9" & Chr(34) & ", " & Chr(34) & "10" &
Chr(34) & ", " & Chr(34) & "11" & Chr(34) & ", " & Chr(34) & "12)"
The variables sTabel and sDateField contain the names of table and
datefield I want to use.
I can't get this ssql to run. Can somebody help me please?