Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO and SQL syntax

Status
Not open for further replies.

jozino01

Technical User
Apr 25, 2003
257
CA
hi,
my vb6 code:

sSQL = "INSERT INTO OUTTURN (CUTID, SIZE, GRADE, LOT, VOLUME, PRICE, REVENUE, PERCENTAGE, INVOICE, CUSTOMER) VALUES ('" & Text2.Text & "', '" & ws1.Cells(i, 1) & "', '" & ws1.Cells(i, 2) & "', '" & ws1.Cells(i, 3) & "', '" & ws1.Cells(i, 4) & "', '" & ws1.Cells(i, 5) & "', '" & ws1.Cells(i, 6) & "', '" & ws1.Cells(i, 7) & "', '" & ws1.Cells(i, 8) & "', '" & ws1.Cells(i, 9) & "'); "
Set rsAccess = New ADODB.Recordset
rsAccess.CursorLocation = adUseClient
rsAccess.Open sSQL, objAccessConnection, adOpenKeyset, adLockOptimistic

generates this SQL command:

INSERT INTO OUTTURN (CUTID, SIZE, GRADE, LOT, VOLUME, PRICE, REVENUE, PERCENTAGE, INVOICE, CUSTOMER) VALUES ('1', '12 X 12 (20)', '2 MER & BTR', 'JGH 4200', '24960', '560', '13977.6', '0.0191063494931', '988', 'SOUTHBEACH-9348');

and it gives me SYNTAX ERROR in my program, but when I copy/paste and run it directly as Access 2000 query it works fine.

Any idea, please?
 
I usually use the Con.Execute command instead of using a recordset whenever I'm doing something other than a select query.

It would go something like this:

Code:
    Dim Con as ADODB.Connection
    Set Con = New ADODB.Connection
    (enter your connection string here)
    (Concatenate your SQL string)      
    Con.ConnectionTimeout = 0
    Con.Open Con.ConnectionString
    Con.Execute(sSQL)


I hope this helps.





Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
i tried your code and I got the same error message as with my original code - "Syntax error in INSERT INTO statement
 
It looks like you have everything in single quotes, and I thought Access was supposed to be double quotes. Other than that, if you have any of those numbers going into a column that is integer/double/number oriented, you would not use the quotes.

Sorry I can't help more.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
The column 'Size' may be the culprit. This is a reserved word, which can cause the query to fail depending on where it's run from.

You could either change the column name or, whenever you refer to it in queries, enclose it in brackets like [Size].
 
thanks for all your input, specially peter0480. it was the word SIZE causing trouble.
 
well, i guess SIZE is a reserved word only for ADO, not for Access...?
 
gmmastros listed that site

anyway, thanks for update.
 
Uh No.....two different urls there. Mimer is more in depth than the Microsoft one.

Glad you got it fixed.

later

Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top