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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Semicolon Error 1

Status
Not open for further replies.

nag9127

Technical User
Mar 15, 2007
76
US
The following code is producing a "missing semicolon at end of SQL statement" error. I can't seem to figure it out so I am asking for some help and possibly an explanation. Thanks in advance!

Code:
Dim strSQL As String

strSQL = ""
strSQL = strSQL & "INSERT INTO ProductionBatchDetailTable"
strSQL = strSQL & "([BatchID], [ItemUsed], [ItemUsedDescription], [QuantityUsed])"
strSQL = strSQL & "VALUES ('" & BatID & "','" & ItemUsed & "','" & Expr1 & "','" & QtyUsed & "')"
DoCmd.RunSQL strSQL
 
Try this:
strSQL = strSQL & "VALUES ('" & BatID & "','" & ItemUsed & "','" & Expr1 & "','" & QtyUsed & "');"

"Business conventions are important because they demonstrate how many people a company can operate without."
 
Tried it and also tried at end of insert statement with no change.
 
Try using

Code:
codedb.execute "INSERT INTO ProductionBatchDetailTable " _
             & "([BatchID], [ItemUsed], [ItemUsedDescription], [QuantityUsed]) " _
             & "VALUES ('" & BatID & "','" & ItemUsed & "','" & Expr1 & "','" & QtyUsed & "')",dbfailonerror

 
Please note the space before the VALUES clause above!

"Business conventions are important because they demonstrate how many people a company can operate without."
 
geonomon:

What space are you referring to. In your post or the in the post below yours?
 
Code:
[QuantityUsed]) " _
             & "VALUES ('" & BatID & "','" & ItemUsed & "','" & Expr1 & "','" & QtyUsed & "')",dbfailonerror

There is a space between [QuantityUsed]) " and "VALUES in Mike's post, but not your original code. That (hopefully) is it. If you are not executing the query with JET then you don't need the semicolon.

"Business conventions are important because they demonstrate how many people a company can operate without."
 
Could any of BatID,ItemUsed,Expr1 and QtyUsed contain an apostrophe ?
If so, use something like this:
Code:
strSQL = strSQL & "VALUES ('" & BatID & "','" & ItemUsed & "','" & Replace(Expr1, "'", "''") & "','" & QtyUsed & "')"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV:

I invoked your solution and it works perfectly. Not only does it clear the apostrophe allowing the INSERT command to run properly, but the inserted field is left in its original state when inserted in the table, without the double '. Can you explain how the data was only changed during the routine and not permanently in the table where it was inserted. Is this all a function of the replace command and how it was placed in the INSERT statement? I guess this is what replace is designed to do. Is that correct? Just trying to understand!
 
The two-single-quotes is a database convention, recognized by the database engine. Smoke & mirrors...

"Business conventions are important because they demonstrate how many people a company can operate without."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top