我是數據庫的新手。我正在創建一個Access數據庫來跟蹤我們公司的庫存動態。我有兩張桌子。一個是當前的庫存庫存,另一個是生產活動引起的消費。更新在每次生產後立即完成。在訪問2013中對條件更新表使用SQL語句
在進行更新之前,我想驗證在庫存狀態和消耗量表中都使用了相同的單位。我試圖做這樣的事情:
Private Sub Command4_Click()
CurrentDb.Execute "SELECT o.Unit, s.Material_Unit" & _
"CASE WHEN o.Unite = s.Material_Unit" & _
"THEN UPDATE tbl_Current_Stock As o INNER JOIN bl_Temp_Raw_Material_Consumption AS s ON o.Raw_Material = s.[Ingredient/Packaging material] Set o.Stock_Level = o.Stock_Level - s.Consumption" & _
" Print'Congratulations! You have successfully updated inventory balance!'" & _
"ElSE PRINT ' Units of source data and targeted data are not matched!'" & _
"Exit Sub" & _
"End" & _
"FROM tbl_Current_Stock As o, bl_Temp_Raw_Material_Consumption AS s"
END sub
但似乎有些錯誤存在。請幫我看看這些代碼。
謝謝。
您正在合併SQL和VBA代碼。並且Access SQL不支持'CASE'語句。考慮閱讀有關MS Access的文檔或教程。 – Parfait