R
Ray S.
I have a function that sends query outputs to excel...
In essence, the relevant part is
Sub QueryToExcel()
' Send Query Output results to Excel
Dim rstOutput As ADODB.Recordset
Dim objXL As Excel.Application
Dim objWS As Excel.Worksheet
Dim fld As ADODB.Field
Dim intCol As Integer
Dim intRow As Integer
Set rstOutput = New ADODB.Recordset
' This is where I keep getting an error
'Run-time error '-2147217900 (80040e14):
'Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
''SELECT', or 'UPDATE'.
rstOutput.Open "QueryOutput", CurrentProject.Connection
the rest of the function lauches Excel, creates a worksheet, copies the
field names, copies over the data, makes worksheet visible, and leaves it open
The problem I'm getting is in just one query. I created it in design view
and it works perfectly well, except when used in this function. I repeat, the
function works with every query I have with the exception of this one:
SELECT "10315" AS FROM, SIDES.OUT AS TO, Sum(SIDES.SidesTO) AS UNITS
FROM SIDES
GROUP BY "10315", SIDES.OUT
HAVING (((Sum(SIDES.SidesTO))>0));
SidesTO is a calculated field using data from other queries
The query just re-names three fields, and groups the results by a numbered
cost center as long as the SidesTO is greater than zero.
Why am I getting the above error message with just this particular query???
In essence, the relevant part is
Sub QueryToExcel()
' Send Query Output results to Excel
Dim rstOutput As ADODB.Recordset
Dim objXL As Excel.Application
Dim objWS As Excel.Worksheet
Dim fld As ADODB.Field
Dim intCol As Integer
Dim intRow As Integer
Set rstOutput = New ADODB.Recordset
' This is where I keep getting an error
'Run-time error '-2147217900 (80040e14):
'Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
''SELECT', or 'UPDATE'.
rstOutput.Open "QueryOutput", CurrentProject.Connection
the rest of the function lauches Excel, creates a worksheet, copies the
field names, copies over the data, makes worksheet visible, and leaves it open
The problem I'm getting is in just one query. I created it in design view
and it works perfectly well, except when used in this function. I repeat, the
function works with every query I have with the exception of this one:
SELECT "10315" AS FROM, SIDES.OUT AS TO, Sum(SIDES.SidesTO) AS UNITS
FROM SIDES
GROUP BY "10315", SIDES.OUT
HAVING (((Sum(SIDES.SidesTO))>0));
SidesTO is a calculated field using data from other queries
The query just re-names three fields, and groups the results by a numbered
cost center as long as the SidesTO is greater than zero.
Why am I getting the above error message with just this particular query???