1

运行以下代码时出现此错误:

错误

Dim sqlSCIQty As String
Dim sqlSCQty As String

sqlSCIQty = "UPDATE [products/stock] INNER JOIN [Stock Conversion Items] " & _
"ON [products/stock].[Product Code] = [Stock Conversion Items].[Result PC] " & _
"SET [Stock Level] = ([Stock Level] + [Quantity]) " & _
"WHERE [Stock Conversion Items].[CutID] = " & Me.txtPCutID.Value & ";"

sqlSCQty = "UPDATE [products/stock] INNER JOIN [Stock Conversion] " & _
"ON [products/stock].[Product Code] = [Stock Conversion].[Source PC] " & _
"INNER JOIN [Stock Conversion Items] " & _
"ON [Stock Conversion].[SCID] = [Stock Conversion Items].[SCID] " & _
"SET [Stock Level] = ([Stock Level] - [Stock Conversion].[Quantity]) " & _
"WHERE [Stock Conversion Items].[CutID] = " & Me.txtPCutID.Value & ";"

Set db = CurrentDb
db.Execute sqlSCIQty, dbFailOnError
db.Execute sqlSCQty, dbFailOnError
Set db = Nothing

我知道第一个语句可以正常运行,但是第二个语句会抛出该错误,我不熟悉如此复杂的更新语句,所以任何有 SQL 知识的人都可以发现任何东西吗?

在此先感谢,
鲍勃 P

4

1 回答 1

1

你可以试试这样

sqlSCQty = "UPDATE (([products/stock] INNER JOIN [Stock Conversion] " & _
"ON [products/stock].[Product Code] = [Stock Conversion].[Source PC]) " & _
"INNER JOIN [Stock Conversion Items] " & _
"ON [Stock Conversion].[SCID] = [Stock Conversion Items].[SCID]) " & _
"SET [Stock Level] = ([Stock Level] - [Stock Conversion].[Quantity]) " & _
"WHERE [Stock Conversion Items].[CutID] = " & Me.txtPCutID.Value & ";"

当您有超过 1 个加入时,您需要括号ms-access

于 2012-10-10T13:31:38.027 回答