473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Syntax error (missing operator) in query expression

Hello! I've written 2 pages: one i HTML format, and second - in ASP. When
I'm posting data from HTML page, I receive this error generated by ASP page:

Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression '' AND ([ID
Platnika]='OFFICE DEPOT')''.

"Office Depot" is the value from form.

When all values are set to "*" the script generates correct results, but if
its value contains any string it generates the error message shown above.
And this is the code of ASP page:

<%
Dim pT1
Dim pT2
Dim pD1
Dim pD2
Dim pD3
Dim pD4
Dim pK1
Dim pD5
Dim pTP1
Dim pTP2

pT1 = request("T1")
pT2 = request("T2")
pD1 = request("D1")
pD2 = request("D2")
pD3 = request("D3")
pD4 = request("D4")
pK1 = request("K1")
pD5 = request("D5")
pTP1 = request("TP1")
pTP2 = request("TP2")

Dim mySQL 'SQL command to execute
Dim objPagingConn 'The ADODB connection object
Dim objPagingRS 'The ADODB recordset object

Set objPagingConn = Server.CreateObject("ADODB.Connection")
objPagingConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("../db2.mdb") & ";"
Set objPagingRS = Server.CreateObject("ADODB.Recordset")

mySQL = ""

If pT1 <> "" And pT2 <> "" Then
mySQL = mySQL & " AND (Data BETWEEN '" & Request ("T1") & "' AND '" &
Request ("T2") & "')"
End If

If pD1 <> "*" Then
mySQL = mySQL & " AND ([Numer faktury]='" & Request ("D1") & "')"
End If

If pD2 <> "*" Then
mySQL = mySQL & " AND ([ID Platnika]='" & Request ("D2") & "')"
End If

If pD3 <> "*" Then
mySQL = mySQL & " AND ([Kategoria]='" & Request ("D3") & "')"
End If

If pD4 <> "*" Then
mySQL = mySQL & " AND ([ID faktury]='" & Request ("D4") & "')"
End If

'If pK1 <> "*" Then
'mySQL = mySQL & " AND ([Kwota]='" & Request ("K1") & "')"
'End If

If pD5 <> "*" Then
mySQL = mySQL & " AND ([Status]='" & Request ("D5") & "')"
End If

If pTP1 <> "" And pTP2 <> "" Then
mySQL = mySQL & " AND ([Termin platnosci] BETWEEN '" & Request ("TP1") & "'
AND '" & Request ("TP2") & "')"
End If

If mySQL <> "" Then
mySQL = "WHERE '" & mySQL & "'"
End If

'---------------------------------------------------------------------------
--------------------------------------------------------
mySQL = "SELECT Data, [Numer faktury], [ID Platnika], Kategoria, [ID
faktury], [Kwota], Status, [Termin platnosci] FROM [Faktury tabela
zbierajaca faktury przychodzace]" & mySQL
'mySQL = mySQL & ";"

objPagingRS.Open mySQL, objPagingConn, 1,1 ', adOpenStatic, adLockReadOnly,
adCmdText %>

<% Do While Not objPagingRS.EOF %>
<% response.write objPagingRS("Numer faktury") %>"><% response.write
objPagingRS("Numer faktury") %><BR>
<% objPagingRS.MoveNext
Loop

objPagingRS.Close
Set objPagingRS = Nothing
objPagingConn.Close
Set objPagingConn = Nothing

%>

Can anybody tell me what is wrong with this code?
What kind of parentes should I use to prevent this error? I'm using '" &
variable & "' ..... Maybe there is another statement?
Please, help!!!
Maciej,
Jul 19 '05 #1
1 11067
See below for the best technique to debug this:
Maciej Paras wrote:
Hello! I've written 2 pages: one i HTML format, and second - in ASP.
When I'm posting data from HTML page, I receive this error generated
by ASP page:

Microsoft JET Database Engine (0x80040E14)
Syntax error (missing operator) in query expression '' AND ([ID
Platnika]='OFFICE DEPOT')''.
<snip>
mySQL = "SELECT Data, [Numer faktury], [ID Platnika], Kategoria, [ID
faktury], [Kwota], Status, [Termin platnosci] FROM [Faktury tabela
zbierajaca faktury przychodzace]" & mySQL
'mySQL = mySQL & ";"


Right here:

Response.Write mySQL

You have no hope of debugging this without knowing exactly what sql
statement you are sending to the database. So, take a look at the result of
the response.write in the browser window. The problem should stand out, but,
if it doesn't, copy and paste the statement from the browser window the the
SQL View of a Query Builder window in Access. Try to run it. At the very
least, you will probably get a better error message.

If you still can't figure it out, show us the sql statement.

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
3
by: Lumpierbritches | last post by:
Syntax Error (missing operator) in query expression =BLANK'S MOLLIE-PRINCE BRUISER-3/14/2004-03 AnimalID is correct. I'm trying to open with a command button or double click the frmAnimal from a...
4
by: khan | last post by:
getting, error, 3075 Syntax Error (Missing Operator) in query expression '8WHERE .=1' Dim TotalQty As Integer TotalQty = DLookup("", "", "=" & Forms!!)
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: T. Wintershoven | last post by:
Hi Can someone please tell me whats wrong with the last line of the query below. The first three lines work fine but when i add the fourth line i get an error message (see text at ERROR...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.