A
AnExpertNovice
3075
Syntax Error (Missing operator) in query expression 'B.LINE_NO NO'
The line that fails is: qdf.SQL = strSql
1. This code has not been modified in many months
2. If the SQL statement is generated, copied, and pasted it into a new query
the query executes properly, once given the ODBC connect string.
3. Since the SQL string works most of the code has been eliminated. The
majority of the code builds the SQL string.
4. IF 'B.LINE_NO NO' is changed to 'B.LINE_NO' (which would require
modifying subsequent queries) the same error occurs but for 'P1 Jan'.
5. The query is referencing an Oracle database hence the FROM DUAL in the
subquery.
Sub BuildKeyLossPqry()
On Error GoTo ErrorRoutine
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strSql As String
strSql = "SELECT B.LINE_DESC, B.LINE_NO NO, LOCATION, YEAR, A.Type, P1
Jan, P2 Feb, P3 Mar, P4 Apr, P5 May, P6 Jun, P7 Jul, P8 Aug, P9 Sep, P10
Oct, P11 Nov, P12 Dec FROM glapps.slc_glrpt_fin_stmt A,
glapps.slc_glrpt_line_struct B WHERE A.LINE_STRUCT = B.LINE_STRUCT AND
A.LINE_NO = B.LINE_NO AND B.LINE_STRUCT = 'C' AND A.TYPE IN ('A', 'B') AND
A.YEAR IN (2004) AND A.LOCATION IN (SELECT 12345 FROM DUAL UNION SELECT
23456 FROM DUAL) ORDER BY B.LINE_NO, LOCATION, YEAR"
Set db = CurrentDb
Set qdf = db.QueryDefs("qryKeyAreaLossData")
qdf.SQL = strSql 'Modify SQL statment in Query "qdf"
<========== Error generated on this line
Set rst = qdf.OpenRecordset()
If rst.EOF Then
MsgBox Prompt:="BuildKeyLossPqry failed - job will abort",
Buttons:=vbOKOnly, Title:="qryKeyAreaLossData"
gboolStopProcessing = True
End If
ExitRoutine:
On Error Resume Next
rst.Close
Set rst = Nothing
qdf.Close
Set qdf = Nothing
db.Close
Set db = Nothing
Exit Sub
ErrorRoutine:
If Not gbooStopProcessing Then
gbooStopProcessing = True
MsgBox "BuildKeyLossPqry failed - job will abort"
End If
Resume ExitRoutine
Resume
End Sub
Syntax Error (Missing operator) in query expression 'B.LINE_NO NO'
The line that fails is: qdf.SQL = strSql
1. This code has not been modified in many months
2. If the SQL statement is generated, copied, and pasted it into a new query
the query executes properly, once given the ODBC connect string.
3. Since the SQL string works most of the code has been eliminated. The
majority of the code builds the SQL string.
4. IF 'B.LINE_NO NO' is changed to 'B.LINE_NO' (which would require
modifying subsequent queries) the same error occurs but for 'P1 Jan'.
5. The query is referencing an Oracle database hence the FROM DUAL in the
subquery.
Sub BuildKeyLossPqry()
On Error GoTo ErrorRoutine
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim strSql As String
strSql = "SELECT B.LINE_DESC, B.LINE_NO NO, LOCATION, YEAR, A.Type, P1
Jan, P2 Feb, P3 Mar, P4 Apr, P5 May, P6 Jun, P7 Jul, P8 Aug, P9 Sep, P10
Oct, P11 Nov, P12 Dec FROM glapps.slc_glrpt_fin_stmt A,
glapps.slc_glrpt_line_struct B WHERE A.LINE_STRUCT = B.LINE_STRUCT AND
A.LINE_NO = B.LINE_NO AND B.LINE_STRUCT = 'C' AND A.TYPE IN ('A', 'B') AND
A.YEAR IN (2004) AND A.LOCATION IN (SELECT 12345 FROM DUAL UNION SELECT
23456 FROM DUAL) ORDER BY B.LINE_NO, LOCATION, YEAR"
Set db = CurrentDb
Set qdf = db.QueryDefs("qryKeyAreaLossData")
qdf.SQL = strSql 'Modify SQL statment in Query "qdf"
<========== Error generated on this line
Set rst = qdf.OpenRecordset()
If rst.EOF Then
MsgBox Prompt:="BuildKeyLossPqry failed - job will abort",
Buttons:=vbOKOnly, Title:="qryKeyAreaLossData"
gboolStopProcessing = True
End If
ExitRoutine:
On Error Resume Next
rst.Close
Set rst = Nothing
qdf.Close
Set qdf = Nothing
db.Close
Set db = Nothing
Exit Sub
ErrorRoutine:
If Not gbooStopProcessing Then
gbooStopProcessing = True
MsgBox "BuildKeyLossPqry failed - job will abort"
End If
Resume ExitRoutine
Resume
End Sub