Michael - There are probably as many ways to solve this as
there are VBA programmers. Here's my solution:
tblProduct
IndexProduct(Autonumber)
Product Name(text)
CurrentInventory(long integer)
tblDelivery
IndexDelivery(Autonumber)
DeliveryDate(Date/Time)
DeliveryCompany(Text, but should be a Lookup)
IndexProduct(Lookup from tblProduct)
ProductCount(long integer)
frmDelivery
holds the tblDelivery fields
The AfterUpdate event triggers on the ProductCount
field.
Code for the ProductCount(AfterUpdate) event:
Private Sub ProductCount_AfterUpdate()
Dim r As Recordset
Dim strSQL As String
Dim lngInventory As Long
strSQL = "SELECT [CurrentInventory] FROM tblProduct " _
& "WHERE [IndexProduct] = " & Me.IndexProduct & ";"
Set r = CurrentDb.OpenRecordset(strSQL)
If r.RecordCount > 0 Then
lngInventory = (r![CurrentInventory] +
Me.ProductCount)
strSQL = "UPDATE tblProduct " _
& "SET tblProduct.CurrentInventory = " &
lngInventory _
& " WHERE ((tblProduct.IndexProduct) = " &
Me.IndexProduct & ");"
CurrentDb.Execute strSQL
End If
End Sub
Make sure that you have your Tools-References set
properly. Mine have "Visual Basic for Applications,
Microsoft 9.0 Object Library, OLE Automation, Microsoft
DAO 3.6 Object Library, and Microsoft Visual Basic for
Applications Extensibility 5.3". Note that the order is
important!
Good luck - Rick