473,387 Members | 1,290 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,387 software developers and data experts.

Syntax error missing operator in query expression

Ok, so I'm by no means good at VBA, and am tryign to make use of some code found on thei nterweb which I reckon does exactly what I want. My problem is that now I've moved the code into my database and changed what I thought were all the appropriate parts and removed the bits I don't want it is broken (of course!).

So the code the debugger points to is:
Expand|Select|Wrap|Line Numbers
  1.     sqlinput = "SELECT * FROM FileInfQry " & BuildFilter
  2.  
  3.     Debug.Print sqlinput
  4.  
  5.     Me.FileInfSubForm.Form.RecordSource = sqlinput
(I've added the debug section, and made the sqlinput variable as part of tryign to get it to work)

The expression quoted as wrong is '[ConsNo] a999x' which is the product of:
Expand|Select|Wrap|Line Numbers
  1.     ' Check for Concession Number
  2.     If Me.txtConcessionNo > "" Then
  3.         varWhere = varWhere & "[ConcessionNo] " & Me.txtConcessionNo & " And "
  4.     End If
If anyone can help it would be greatly appreciated - my progress has been pretty glacial today!
Jun 26 '13 #1

✓ answered by Seth Schrock

Ah, so ConcessionNo is a text field and not a number field. Then you will need to add some single quotes inside your double quotes like this:
Expand|Select|Wrap|Line Numbers
  1. varWhere = varWhere & "[ConcessionNo] = '" & Me.txtConcessionNo & "' And "
Just curious, do you add anything onto the end of this? I ask because as I see it, the SQL code will get left with an AND at the end and I don't see anything that would put additional criteria after it, nor take it away.

Also, if this doesn't work, then I would like to see the output from your Debug.Print to make sure that it is ending up correctly.

5 1931
Seth Schrock
2,965 Expert 2GB
In your second code group shown, add an equals sign after the [ConcessionNo], but before the ending double quote.

Expand|Select|Wrap|Line Numbers
  1. ' Check for Concession Number
  2.     If Me.txtConcessionNo > "" Then
  3.         varWhere = varWhere & "[ConcessionNo] = " & Me.txtConcessionNo & " And "
  4.     End If
Jun 26 '13 #2
Hi Seth,
Thanks for the reply, that has stopped the code error'ing which is a massive relief!
However, now I get a pop-up box asking for the search term - the code originally just used the value input ("a999x" for example) AS the search term, now I get a popup with "a999x" and a data entry box I have to put it in AGAIN for the search to work? I've clearly deleted or added soemthing weird somewhere :/

Am I going to need to post more info from the programme?

Cheers, Rohan
Jun 27 '13 #3
Seth Schrock
2,965 Expert 2GB
Ah, so ConcessionNo is a text field and not a number field. Then you will need to add some single quotes inside your double quotes like this:
Expand|Select|Wrap|Line Numbers
  1. varWhere = varWhere & "[ConcessionNo] = '" & Me.txtConcessionNo & "' And "
Just curious, do you add anything onto the end of this? I ask because as I see it, the SQL code will get left with an AND at the end and I don't see anything that would put additional criteria after it, nor take it away.

Also, if this doesn't work, then I would like to see the output from your Debug.Print to make sure that it is ending up correctly.
Jun 27 '13 #4
Hi Seth,
Sorry, I probably should have known it was an input value rather than text box content - this is the downside of using other people's code!

The extra ANDs are presumably surplus to requirements from the other code - I removed things I didn't think I'd need, but clearly didn't remove enough (as well as too much!)...

Having just gone through the various search fields to test I haven't broken anyhting else I have discovered a problem - I can't search for a date! I'm guessing the '/' in the date format are the issue - but there must be a way around that? I have formatted them 'dd/mm/yyyy'.

Thanks for the help, you're a star! :)

Cheers, Rohan
Jun 27 '13 #5
Seth Schrock
2,965 Expert 2GB
No problem. While new questions do need to be asked in another thread, I will try to point you in the right direction. Dates need to be surrounded in pound signs (#). If this doesn't provide enough information, start a new thread and post the SQL that is giving you problems as well as what exactly you are trying to do and someone will be able to help you out.
Jun 27 '13 #6

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.