I am getting an Error 3141 select statement includes a reserved word or an argument name.
I am trying to rewrite an crosstab query into an strSQL statement this is my first attempt doing this. I keep on getting this error, I have tried changing the order of the statements with no luck. Any help is appreciated. When I run the query it outputs the following data:Col 1 - uci, Col 2 provname, Col3 -16 are the billpd.
The error is highlighted in Red
Original crosstab query
Converted code
I am trying to rewrite an crosstab query into an strSQL statement this is my first attempt doing this. I keep on getting this error, I have tried changing the order of the statements with no luck. Any help is appreciated. When I run the query it outputs the following data:Col 1 - uci, Col 2 provname, Col3 -16 are the billpd.
The error is highlighted in Red
Original crosstab query
Code:
TRANSFORM Sum(PROC_ReadingProvider.proc) AS SumOfproc
SELECT PROC_ReadingProvider.uci, PROC_ReadingProvider.readingprovname
FROM PROC_ReadingProvider
WHERE (((PROC_ReadingProvider.billpd)>357))
GROUP BY PROC_ReadingProvider.uci, PROC_ReadingProvider.readingprovname
ORDER BY PROC_ReadingProvider.readingprovname, PROC_ReadingProvider.billpd
PIVOT PROC_ReadingProvider.billpd;
Converted code
Code:
Public Function GetData()
Dim strSQL As String
Dim Z As Integer
Dim rst As Recordset
Dim iRow As Integer
strSQL = "SELECT tbl_RegPr.uci as 1, tbl_RegPr.readingprovname as 2 ,tbl_RegPr.billpd as 3,tbl_RegPR.billpd as 4" & _
"tbl_RegPr.billpd as 5, tbl_RegPr.billpd as 6, tbl_RegPr.billpd as 7, tbl_RegPr.billpd as 8, tbl_RegPr.billpd as 9," & _
"tbl_RegPr.billpd as 10, tbl_RegPr.billpd as 11, tbl_RegPr.billpd as 12, tbl_RegPr.billpd as 13, tbl_RegPr.billpd as 14, " & _
"FROM PROC_ReadingProvider tbl_RegPr " & _
"GROUP BY tbl_RegPr.uci, tbl_RegPr.readingprovname,tbl_RegPr.billpd " & _
"ORDER BY tbl_RegPr.readingprovname, tbl_RegPr.billpd; "
[Red] Set rst = CurrentDb.OpenRecordset(strSQL, dbopensnapshot)[/red]
'Verify the recordcount counter is set at record 1
If (rst.RecordCount > 0) Then
With rst
.MoveLast
.MoveFirst
End With
iRow = 5
'Counter to loop through all records
For Z = 1 To rst.RecordCount
With goXL.ActiveSheet
.Cells(iRow, 1) = rst![1]
.Cells(iRow, 2) = rst![2]
.Cells(iRow, 3) = rst![3]
.Cells(iRow, 4) = rst![4]
.Cells(iRow, 5) = rst![5]
.Cells(iRow, 6) = rst![6]
.Cells(iRow, 7) = rst![7]
.Cells(iRow, 8) = rst![8]
.Cells(iRow, 9) = rst![9]
.Cells(iRow, 10) = rst![10]
.Cells(iRow, 11) = rst![11]
.Cells(iRow, 12) = rst![12]
.Cells(iRow, 13) = rst![13]
.Cells(iRow, 14) = rst![14]
.Cells(iRow, 15) = rst![15]
.Cells(iRow, 16) = rst![16]
End With
iRow = iRow + 1
rst.MoveNext
Next
End If
End Function