423,103 Members | 1,428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,103 IT Pros & Developers. It's quick & easy.

syntax error

P: n/a
I get this error and can't figure out the correct syntax.
Doesn't seem to make a difference changing the quotes around.
Thanks!
---------------------
Syntax error (missing operator) in query expression 'GenKTitles.Title= White
Christmas'.
---------------------
<%
Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""
Set rsResults = DataConn.Open(SQL)
%>
Jul 19 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
> SQL = SQL & " WHERE GenKTitles.Title= "" + SearchTerm + ""
Jul 19 '05 #2

P: n/a
> SQL = SQL & " WHERE GenKTitles.Title= "" + SearchTerm + ""
Jul 19 '05 #3

P: n/a
or

SQL = SQL & " WHERE GenKTitles.Title= " & Chr(34) & Trim(SearchTerm) &
Chr(34)

Also check www.aspfaq.com to handle the problem with ' and " in string. In
my country name or often like D'haese whta cause a problem when you surround
the searchstring by "'" + searchstring + "'"
Jul 19 '05 #4

P: n/a
or

SQL = SQL & " WHERE GenKTitles.Title= " & Chr(34) & Trim(SearchTerm) &
Chr(34)

Also check www.aspfaq.com to handle the problem with ' and " in string. In
my country name or often like D'haese whta cause a problem when you surround
the searchstring by "'" + searchstring + "'"
Jul 19 '05 #5

P: n/a
> SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""

Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #6

P: n/a
> SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""

Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #7

P: n/a
Sorry, that last + should be &

Shank, + is addition, while it doubles as string concatenation in VBScript,
you should try to always use & to avoid issues.

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""


Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)

Jul 19 '05 #8

P: n/a
Sorry, that last + should be &

Shank, + is addition, while it doubles as string concatenation in VBScript,
you should try to always use & to avoid issues.

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""


Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)

Jul 19 '05 #9

P: n/a
That worked! Thanks! But now I'm getting this error...
The query should return valid records. What object is missing?
------------------------
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'open(...)'

------------------------
<%
Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"
Set rsResults = DataConn.Open(SQL) <-- ERROR on this line
%>

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:u0****************@TK2MSFTNGP09.phx.gbl...
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""


Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)

Jul 19 '05 #10

P: n/a
That worked! Thanks! But now I'm getting this error...
The query should return valid records. What object is missing?
------------------------
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'open(...)'

------------------------
<%
Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"
Set rsResults = DataConn.Open(SQL) <-- ERROR on this line
%>

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:u0****************@TK2MSFTNGP09.phx.gbl...
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""


Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)

Jul 19 '05 #11

P: n/a
You created an instance of a Recordset not a Connection...
Set DataConn = Server.CreateObject("ADODB.Recordset")

Bob Lehmann

"shank" <sh***@tampabay.rr.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
That worked! Thanks! But now I'm getting this error...
The query should return valid records. What object is missing?
------------------------
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'open(...)'

------------------------
<%
Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"
Set rsResults = DataConn.Open(SQL) <-- ERROR on this line
%>

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:u0****************@TK2MSFTNGP09.phx.gbl...
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""


Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)


Jul 19 '05 #12

P: n/a
You created an instance of a Recordset not a Connection...
Set DataConn = Server.CreateObject("ADODB.Recordset")

Bob Lehmann

"shank" <sh***@tampabay.rr.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
That worked! Thanks! But now I'm getting this error...
The query should return valid records. What object is missing?
------------------------
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'open(...)'

------------------------
<%
Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"
Set rsResults = DataConn.Open(SQL) <-- ERROR on this line
%>

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:u0****************@TK2MSFTNGP09.phx.gbl...
SQL = SQL & "WHERE GenKTitles.Title= " + SearchTerm + ""


Try:

SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"

--
http://www.aspfaq.com/
(Reverse address to reply.)


Jul 19 '05 #13

P: n/a
> Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"
Set rsResults = DataConn.Open(SQL) <-- ERROR on this line


Where are you getting this syntax from? It's all wrong. Please tell us
where it came from so we can correct the source and ask them to stop
providing faulty code.

First off, you created an ADODB.Recordset as an object with conn in the
name. Surely that's a mistake. Second, a connection object returns a
recordset object to rsResults by calling connectionObject.EXECUTE(sql), not
connectionObject.OPEN(sql). How about this:

SearchTerm = "White Christmas"
set conn = CreateObject("ADODB.Connection")
conn.open MM_GenKAccess_STRING
sql = "SELECT ... "
set rsResults = conn.execute(sql)

And PLEASE, PLEASE, PLEASE STOP USING SELECT * !!!!!!!!!!!!!!!!! And it
wouldn't hurt to stop letting Macromedia products create big, unreadable and
error-prone variable names, either.

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #14

P: n/a
> Dim DataConn, SQL
SearchTerm = "White Christmas"
Set DataConn = Server.CreateObject("ADODB.Recordset")
DataConn.ActiveConnection = MM_GenKAccess_STRING
SQL = "SELECT GenKStock.*, GenKTitles.* "
SQL = SQL & "FROM GenKStock INNER JOIN GenKTitles ON GenKStock.OrderNo =
GenKTitles.ItemNumber "
SQL = SQL & "WHERE GenKTitles.Title= '" & SearchTerm + "'"
Set rsResults = DataConn.Open(SQL) <-- ERROR on this line


Where are you getting this syntax from? It's all wrong. Please tell us
where it came from so we can correct the source and ask them to stop
providing faulty code.

First off, you created an ADODB.Recordset as an object with conn in the
name. Surely that's a mistake. Second, a connection object returns a
recordset object to rsResults by calling connectionObject.EXECUTE(sql), not
connectionObject.OPEN(sql). How about this:

SearchTerm = "White Christmas"
set conn = CreateObject("ADODB.Connection")
conn.open MM_GenKAccess_STRING
sql = "SELECT ... "
set rsResults = conn.execute(sql)

And PLEASE, PLEASE, PLEASE STOP USING SELECT * !!!!!!!!!!!!!!!!! And it
wouldn't hurt to stop letting Macromedia products create big, unreadable and
error-prone variable names, either.

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.