Solved

Syntax Error (Missing Operator) in query expression '

Posted on 2012-03-27
4
624 Views
Last Modified: 2012-03-27
Syntax Error (Missing Operator) in query expression 'BNo = '

in B_Detail Table
BNo ( Data Type is Number  and  Field size is Double

                 Set CMLrRs = Nothing
                 If CMLrRs.State = 1 Then CMLrRs.Close
                 CMLrRs.Open "select * from B_Detail where BNo = " & Text1(0) & "", con, adOpenKeyset, adLockOptimistic

Open in new window


Why i am getting this error
0
Comment
Question by:crystal_Tech
  • 2
4 Comments
 
LVL 11

Assisted Solution

by:rajvja
rajvja earned 125 total points
ID: 37771463
CMLrRs.Open "select * from B_Detail where BNo = " & CINT(Text1(0)) & "", con, adOpenKeyset
0
 
LVL 11

Expert Comment

by:rajvja
ID: 37771468
Try storing the query in a variable and display how it is forming the query

Or Text(o) might be returning as text. Convert it to INT
0
 
LVL 61

Accepted Solution

by:
mbizup earned 125 total points
ID: 37771471
Most likely becuse Text1(0) is null.  Try this:

                 Set CMLrRs = Nothing
                 If CMLrRs.State = 1 Then CMLrRs.Close
                 CMLrRs.Open "select * from B_Detail where BNo = " & NZ(Text1(0),0) & "", con, adOpenKeyset, adLockOptimistic


Ot if Text1 is a textbox, do you simply mean this?

                 Set CMLrRs = Nothing
                 If CMLrRs.State = 1 Then CMLrRs.Close
                 CMLrRs.Open "select * from B_Detail where BNo = " & NZ(Text1,0) & "", con, adOpenKeyset, adLockOptimistic
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 37771505
I would agree with mbizup, that Text1(0) is NULL.

Using the NZ() function to convert that NULL value to a numeric should resolve that issue.

However, you may find that you don't get the results that you are looking for using this method.  Double precision numbers are frequently off in the way they are stored in the database because of the limits of representing decimal places as binary values.  So when you query for BNo = 1.3456, what may actually be stored in the database is 1.3455999, and since those two values are not precisely the same, the record would not be returned by your query.

If your BNo values will all be integers, I would strongly recommend that you change the datatype from double to integer or Long Int data type.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Attachment field in SQL 3 28
Modal form 11 30
which modules are active in VB6 project? 6 10
Copy a range from 1..n excel sheets to one destination sheet 2 31
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question