Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code in VB 6.0 . The code is supposed to add details in a column in a datagrid1 and display the total in a textbox below the column.
Help me I'm getting a run-time error '-2147217900(80040e14) syntax error(missing operator) in
query expression.

VB
Dim DB As Connection

Set DB = New Connection
DB.CursorLocation = adUseClient

DB.Open "provider=microsoft.jet.oledb.4.0;DATA SOURCE=c:\WAREHOUSE _&   INVENTORY\warehousedata13.mdb;jet oledb:database password=malachi45"

Dim rsTotal5 As ADODB.Recordset
Set rsTotal5 = New ADODB.Recordset

Dim totalpairs As Integer
totalpairs = 0

rsTotal5.ActiveConnection = DB

rsTotal5.Source = DB

rsTotal5.Open "SELECT*FROM TransferDetails WHERE Transfer_Number '" + _& txtTransferNumber.Text + "'", DB, adOpenStatic, adLockOptimistic

rsTotal5.MoveFirst

Do While Not rsTotal5.EOF
   totalpairs = totalpairs + Val(rsTotal5.Fields("TotalPairs"))
   rsTotal5.MoveNext
Loop
   rsTotal5.Close

   txtTotalPairs2.Text = totalpairs
Posted
Updated 16-Jul-13 3:52am
v3
Comments
[no name] 16-Jul-13 9:53am    
"SELECT*FROM TransferDetails WHERE Transfer_Number="

1 solution

VB
"SELECT * FROM TransferDetails WHERE Transfer_Number = '" + txtTransferNumber.Text + "'"


or

VB
"SELECT * FROM TransferDetails WHERE Transfer_Number LIKE '" + txtTransferNumber.Text + "'"


You forgot = or LIKE

Better put a couple of spaces around * as well!
 
Share this answer
 
v7
Comments
Member 9977207 16-Jul-13 10:09am    
Thank you for your help the code has worked
Johnny J. 16-Jul-13 11:11am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900