2016-07-11 12 views
0

私はInventoryTransactionと呼ばれるテーブルに値を置き、完全に正常に機能する関数を持っています。ただし、InventoryTransactionに追加されたレコードを使用して別のテーブルを更新する必要があります。しかし、私はそれは私にエラーを与え続けて値を更新しようとしている困難を抱えている 、任意のガイダンスは関数からVBAの別のテーブルにSQLの更新にアクセス

を理解されるであろう

エラーメッセージは次のとおりです。「式に未定義関数 『IT.QuantityWHERE』」

Function EditTransaction(IT As InventoryTransaction, Optional CustomerOrderID, Optional PurchaseOrderID) As Boolean 
Dim rsw As New RecordSetWrapper 
Dim SQL As String 




If rsw.OpenRecordset("InventoryTransaction", "[TransactionID] = " & IT.InventoryID) Then 
    With rsw.Recordset 
     If IT.TransactionType <= 0 Then 
      Exit Function 
     ElseIf IT.InventoryID = m_cNew_InventoryID Then 
      rsw.AddNew 
     ElseIf .EOF Then 
      Exit Function 
     Else 
      rsw.Edit 
     End If 


     ![ItemID] = IT.ProductID 
     ![TransactionQty] = IT.Quantity 
     ![TransactionType] = IT.TransactionType 
     ![LocationID] = IT.LocationID 
     ![Time] = Now() 

     EditTransaction = rsw.Update 

     If IT.InventoryID = m_cNew_InventoryID Then 
      rsw.Recordset.Bookmark = rsw.Recordset.LastModified 
      IT.InventoryID = ![TransactionID] 
     End If 


End With 

       SQL = "UPDATE Inventory " & _ 
       "SET Inventory.Qty = Inventory.Qty + IT.Quantity" & _ 
       "WHERE (Inventory.ItemID = IT.ProductID And Inventory.LocationID = IT.LocationID)" 
     DoCmd.RunSQL SQL 
End If 
+0

具体的には何が違うのですか? –

+0

エラー:「定義されていない関数 'IT.QuantityWHERE」が式 – cxk

答えて

0

あなたのSQLを修正:

:レコードセットを開いている間

SQL = "UPDATE Inventory " & _ 
     "SET Inventory.Qty = Inventory.Qty + IT.Quantity " & _ 
     "WHERE (Inventory.ItemID = IT.ProductID And Inventory.LocationID = IT.LocationID)" 
DoCmd.RunSQL SQL 

また、あなたはどのような状況の下で終了機能すべき

With rsw.Recordset 
    ' Do stuff. 
    ' Don't exit function. 
    ' Do more stuff. 
    .Close 
End With 
Set rsw = Nothing  
' Exit function now allowed. 
+0

ありがとうございます。私はSQLコードを変更しましたが、問題は、1つのレコードのみを更新しようとしています。 。。? しかし、今、私のInventoryTransactions内のすべてのレコードを更新しようとしている私が何か間違ったことをやっている – cxk

+0

これはSQLです:INNERはInventoryTransaction ONに[JOINの 'code' SQL = "UPDATEインベントリ" &_ 」 [InventoryID] "&_ " SET [Inventory]。[数量] = [在庫数] + [InventoryTransaction]。[TransactionQty] "&_ " [LocationID] = [InventoryTransaction] ([Inventory]。[ItemID] = [InventoryTransaction]。[ItemID])および([Inventory]。[LocationI D] = [InventoryTransaction]。[LocationID])) " DoCmd.RunSQL SQL – cxk

1

あなたのUPDATEステートメントはそう言っているので、すべてのレコードを更新しています。 最新のUPDATEステートメントに切り替えた理由がわかりません。 Gustavが提供するUPDATEステートメントに固執する必要があります。

関連する問題