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

Syntax Error

im trying to run this code from a button but i get an error "syntax error(missing operator)in a query expression": where do i go wrong?

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmNotes", , , "SerialNumber='" & Me.SerialNumber.Value & "'" & "ntsTime='" & Me.ntsTime.Value & "'"
Aug 10 '11 #1

✓ answered by NeoPa

That sort of response is fine Dan. It has errors, but clearly you've made an attempt from what's been posted already.

Your (technical) mistake was to leave the "AND" part of the string outside of the string itself (See How to Debug SQL String for tips on how to avoid such issues in future).

Your code should look like :
Expand|Select|Wrap|Line Numbers
  1. Public Sub frmNotes()
  2.     Dim strWhere As String
  3.  
  4.     strWhere = "([ntsTime]=#" & Me.ntsTime & "#) AND " & _
  5.                "([equipGovSerialNumber]='" & Me.equipGovSerialNumber & "')"
  6.     DoCmd.OpenForm "frmNotes", , , strWhere
  7. End Sub

13 1512
Rabbit
12,516 Expert Mod 8TB
If you evaluate your filter string, you get
Expand|Select|Wrap|Line Numbers
  1. SerialNumber='some serial number'ntsTime='some time'
Aug 10 '11 #2
Yes... the code brings the error with the correct result but wont open the form im trying to filter due to the error.
Aug 10 '11 #3
Rabbit
12,516 Expert Mod 8TB
Right, so you need to fix your filter string.
Aug 10 '11 #4
an example will do or are you saying the code is okay?
Aug 10 '11 #5
NeoPa
32,556 Expert Mod 16PB
Neither. He's saying that he's highlighted the issue and you now need to resolve it. If you can see nothing obviously wrong with the string value in post #2 then you need to find out some very basics. The Help system is where you should be looking for that. See Context-Sensitive Help.
Aug 10 '11 #6
Frinavale
9,735 Expert Mod 8TB
Excuse me for asking (this is not my area of expertise) but isn't the problem with the "where" parameter (as opposed to the filter parameter)

Just looking at the MSDN article about the OpenForm Method (Access 2003 VBA Reference)...it looks like the 4th parameter is the "where condition".

The "where" condition is incorrect.
You need a SQL operator for the where condition...

For example:

Expand|Select|Wrap|Line Numbers
  1. SerialNumber='some serial number' AND ntsTime='some time'
Here's another example:

Expand|Select|Wrap|Line Numbers
  1. SerialNumber='some serial number' OR ntsTime='some time'
The AND and the OR part of the where clause are operators :)

There are other operators that you can use...look up the SQL Where clause for more info.
Aug 10 '11 #7
Rabbit
12,516 Expert Mod 8TB
Yes sorry, I meant where. I mix the two up sometimes.
Aug 10 '11 #8
NeoPa
32,556 Expert Mod 16PB
Actually, the WhereCondition parameter is also known as the Filter string. This should not be confused with the FilterName parameter of course, which is a reference to a filtering query instead.
Aug 11 '11 #9
this works fine when tested:
Expand|Select|Wrap|Line Numbers
  1. Public Sub frmNotes()
  2. DoCmd.OpenForm "frmNotes", , , "ntsTime=#" & Me.ntsTime.Value & "#"
  3. End Sub
this also works when tested separately:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmNotes", , , "equipGovSerialNumber='" & Me.equipGovSerialNumber.Value & "'"
now the problem comes when im trying to mix them together like:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmNotes", , , "equipGovSerialNumber='" & Me.equipGovSerialNumber.Value & "'" AND "ntsTime=#" & Me.ntsTime.Value & "#"
i get a (Type mismatch)error, im a learner and this is confusing me.
Aug 11 '11 #10
Narender Sagar
189 100+
Type mismatch means : when you are comparing/joining any two tables, the "data type" must be same (You can not join "Text" data type with numeric Data Type.)
So please check Data type of joining fields.
Aug 11 '11 #11
okay... here i want to filter a form by Time(ntsTime) and serial number is Text data type and thats where i get stuck with the coding the two in one code/Line.
Aug 11 '11 #12
NeoPa
32,556 Expert Mod 16PB
That sort of response is fine Dan. It has errors, but clearly you've made an attempt from what's been posted already.

Your (technical) mistake was to leave the "AND" part of the string outside of the string itself (See How to Debug SQL String for tips on how to avoid such issues in future).

Your code should look like :
Expand|Select|Wrap|Line Numbers
  1. Public Sub frmNotes()
  2.     Dim strWhere As String
  3.  
  4.     strWhere = "([ntsTime]=#" & Me.ntsTime & "#) AND " & _
  5.                "([equipGovSerialNumber]='" & Me.equipGovSerialNumber & "')"
  6.     DoCmd.OpenForm "frmNotes", , , strWhere
  7. End Sub
Aug 11 '11 #13
thanks Neopa.. its works wonders, i didn't even change a thing. thanks again. till we meet again. my regards
Aug 11 '11 #14

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

Similar topics

14
by: sam | last post by:
When I run this SQL query: SELECT u.*, o.* FROM users u, orders o WHERE TO_DAYS(o.order_date) BETWEEN TO_DAYS('2003-09-20')-10 AND TO_DAYS('2003-09-20')+10
1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
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"...
1
by: Donald Canton | last post by:
Hi, I'm using Bjarne's book to learn C++ and am stuck on the Calc program in Section 6. Everything works fine except when I try to use istringstream to parse a token from the command line. I...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
2
by: david | last post by:
Anyone could give me a hand about this syntax error? Thank you. David Source Code: Dim conn As New SqlConnection(strConn) Dim daAngio As New SqlDataAdapter(strSelectStatement, conn) 'Create a...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
4
by: nickyeng | last post by:
i calling this piece of java code in jsp : List<Customer> list = Customer.listby_page(currentRs); ... ... then it gives me the following error:
0
by: Timothy Grant | last post by:
On Thu, Aug 28, 2008 at 1:40 AM, Alexis Boutillier <alexis.boutillier@arteris.comwrote: So if you were writing C code and the file failed to compile you would still expect to have a working...
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.