473,467 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Syntax error (missing operator) in query expression...

4 New Member
Hi All,

I am getting the following MS Access error:

Syntax error (missing operator) in query expression '(((BOQ.Description) =Site Establishment Dismantle))'

For the following VBA statement:

Expand|Select|Wrap|Line Numbers
  1. Dim name As String
  2. name = "Site Establishment Dismantle"
  3. Set rs1 = db1.OpenRecordset("select BOQ.Description from BOQ where " & " (((BOQ.Description) =" & Qu & name & Qu & "))", DB_OPEN_DYNASET)
The statement is in one line.

BOQ is a Table and Description is a Text Field Name.

I would like to select the record in the table that matches name string and then be able to access other field names of that record.

My alternative is using a do loop to search through the entire table...I would like to cut down on this wasted cpu overhead...

I am obviously doing something wrong. Please can anyone help?

Thanks!
Oct 20 '11 #1

✓ answered by Stewart Ross

The error message is showing that the string literal you want to use in the WHERE clause is present, but it is not enclosed in single-quotes - hence the error. You have a constant or variable Qu defined for this purpose, but whatever it contains it is not a single quote:

Expand|Select|Wrap|Line Numbers
  1. where " & " (((BOQ.Description) =" & Qu & name & Qu & ")
You can simply put the single quotes directly into the SQL string before and after the inclusion of the string literal, like this:

Expand|Select|Wrap|Line Numbers
  1. where Description ='" & name & "';",  DB_OPEN_DYNASET))

I have also removed the unnecessary bracketing and table-name qualification from the where clause, something which is usually added by the query designer and inadvertently copied if you use the SQL created by the query designer as a guide.

-Stewart

6 5608
Stewart Ross
2,545 Recognized Expert Moderator Specialist
The error message is showing that the string literal you want to use in the WHERE clause is present, but it is not enclosed in single-quotes - hence the error. You have a constant or variable Qu defined for this purpose, but whatever it contains it is not a single quote:

Expand|Select|Wrap|Line Numbers
  1. where " & " (((BOQ.Description) =" & Qu & name & Qu & ")
You can simply put the single quotes directly into the SQL string before and after the inclusion of the string literal, like this:

Expand|Select|Wrap|Line Numbers
  1. where Description ='" & name & "';",  DB_OPEN_DYNASET))

I have also removed the unnecessary bracketing and table-name qualification from the where clause, something which is usually added by the query designer and inadvertently copied if you use the SQL created by the query designer as a guide.

-Stewart
Oct 20 '11 #2
DuncanMcCloud
4 New Member
Thanks Stewart.

I have the following to add:

User:
check your bracketing
Expand|Select|Wrap|Line Numbers
  1. Dim name As String
  2. dim strSQL as string
  3. name = "Site Establishment Dismantle"
  4. strSQL = "SELECT Description from BOQ WHERE Description='"  & name & "'"
  5. Set rs1 = db1.OpenRecordset(strSQL, DB_OPEN_DYNASET)
just guessing qu is a variable defiend as ' or ".. you coudl use the CHR function if you prefer

..although why you would want to retrieve the description from the table when you already know the description AND are usign it as the filter in the WHERE clause baffles me


Me:
Thanks, it passes now, but now I have a new error

Expand|Select|Wrap|Line Numbers
  1. Set rs1 = db1.OpenRecordset("select Description from BOQ where Description ='" & name & "'", DB_OPEN_DYNASET)
  2. MsgBox (rs1!Rate)
Access returns saying "Item not found in this collection." when it executes the last line. The field is there and it is populated in the table...
I have tried it with other Descriptions & field names as well, same error.


User:

Your query is:
Expand|Select|Wrap|Line Numbers
  1. select Description from BOQ where...
Which means that Description will be the only column available in the resulting Recordset.

If you want to have the column Rate included in the recordset, it must be present in the SELECT column list of the query (you only receive what you asked for):
Expand|Select|Wrap|Line Numbers
  1. SELECT Description, Rate from BOQ where...


Problem is solved,
Thank you
Oct 20 '11 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Please note also that all you are SELECTing is the string you have compared - the description. This is not likely to be of much assistance to you.

It is easier to see such logic errors if you split your code up a little and use a separate string for the SQL, like this:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. strSQL = "SELECT Description from BOQ "
  3. strSQL = strSQL & "WHERE Description = '" & name & "';" 
  4. Set rs1 = db1.OpenRecordset(strSQL, DB_OPEN_DYNASET)
-Stewart
Oct 20 '11 #4
DuncanMcCloud
4 New Member
Thanks for the tip Stewart. It is something I would have to get used to :)
Oct 20 '11 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Good tips from Stewart (of course) but I'd add an alternative that you might use instead. It follows the same main principles though :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. strSQL = "SELECT Description from BOQ " & _
  3.          "WHERE Description = '" & name & "';"
Use of the continuation character (_) enables you to see what you're working with more clearly and easily.

Here's something else to check on when dealing with any SQL problems - How to Debug SQL String - I expect you'll find this helps you solve many of them without the need for questions (Though we're here for any that need it).

PS. May I suggest that post #2 is a prime candidate for the Best Answer button for this thread ;-)
Oct 20 '11 #6
DuncanMcCloud
4 New Member
Thank you for the tips :)
Oct 20 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: alexz | last post by:
valuA = (request.form("toadd")) If valuA = "" then SQL = "UPDATE CourseReg SET attended='Active' WHERE ID IN("&request.form("toadd")&")" Set RS = MyConn.Execute(SQL) End If MyConn.Close Set...
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!!)
1
by: Justin R | last post by:
Hey I am really stuck and can't figure out what is wrong here is the code line and surrounding code, if anyone can help i would appreciate it. Thanks This first line is the line that has a problem...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.