I have 2 tables: (1)Items: ItemID, ItemName, ItemQuantity (2) Transaction: TransID, ItemID, OperationCode (in, Out), TransQuantity. The two tables are related by ItemCode (1 to many). I designed a form in which there is a combo box based on the item table. The combobox displays ItemName and hides ItemCode. What I want is this: when user selects an item I want that specific record to be updated using the quantity that I user enters in the form. Whenever I select any item the updated record is always the FIRST one. This is the code:
Option Compare Database
Private Sub Command8_Click( )
Dim db As Database
Dim rs1 As Recordset
Dim rs2 As Recordset
Set db = CurrentDb
Set rs1 = db.OpenRecordse t("TransT")
Set rs2 = db.OpenRecordse t("ItemT")
rs1.AddNew
'rs1!itemID = ItemList.ItemsS elected(itemnam e)
rs1!TransQty = Quantity
'MsgBox (rs2!itemname)
rs1.Update
rs1.Close
rs2.Edit
rs2!ItemQty = rs2!ItemQty + Quantity
rs2.Update
rs2.Close
Set db = Nothing
MsgBox ("Done!")
End Sub
Option Compare Database
Private Sub Command8_Click( )
Dim db As Database
Dim rs1 As Recordset
Dim rs2 As Recordset
Set db = CurrentDb
Set rs1 = db.OpenRecordse t("TransT")
Set rs2 = db.OpenRecordse t("ItemT")
rs1.AddNew
'rs1!itemID = ItemList.ItemsS elected(itemnam e)
rs1!TransQty = Quantity
'MsgBox (rs2!itemname)
rs1.Update
rs1.Close
rs2.Edit
rs2!ItemQty = rs2!ItemQty + Quantity
rs2.Update
rs2.Close
Set db = Nothing
MsgBox ("Done!")
End Sub
Comment