Syntax Error in INSERT INTO Statement

Quadcrazi

New member
Local time
Today, 15:17
Joined
Jan 22, 2025
Messages
11
Hello
I am currently working on Invoicing in my db. When I click the button to insert my 'Item' into the 'InvoicedItemsSub' I get a Syntax Error in INSERT INTO Statement. I copied this from another db I have that works fine and just changed the information accordingly. I'm pretty new at this and can't see what the problem is. Can anyone help? Thanks in advance.

SQL:
docmd.runsql "Insert INTO tbl_InvoiceItems" & _
"(InvID,ItmID,ItmSID,ItmSaleBalance,InvItmQty,InvItmPrice) VALUES " & _
"(" & me.Parent!InvID & "," & me.ItmID & "," & me.ItmSID & "," & saleInv & "," & saleInv & "," & me.ItmSAmount & ");"
 
Try this sql statement instead of yours to output the sql and check if the values added into maybe contain incompatible content like comma for example:
Code:
Debug.Print "Insert INTO tbl_InvoiceItems" & _
"(InvID,ItmID,ItmSID,ItmSaleBalance,InvItmQty,InvItmPrice) VALUES " & _
"(" & me.Parent!InvID & "," & me.ItmID & "," & me.ItmSID & "," & saleInv & "," & saleInv & "," & me.ItmSAmount & ");"
 
Why are you trying to add the same value twice (saleinv) to balance and quantity?
 
Put it all into a string variable and DEBUG.PRINT it until you get it correct. Then use that variable in the command.
 
I'll give you a hint: Sometimes the VBA compiler is a bit dumb - like "as a box of rocks" dumb. Sometimes it requires a space after a named item even though another syntax clue such as a "(" character is already present, because without the space, it looks like a function call. But the ideas given by my colleagues as a debugging method should help you find that little bug-a-boo.
 

Users who are viewing this thread

Back
Top Bottom