I am creating an asset management database with 2 tables (Assets and AssetMovements) and one form (Assets). I need to keep records of every asset movement, so every time a
The button has a click event that is fired when you click it. Use VBA to write some code that is executed when the button is clicked.
When you click the button, you would then save the record to Assets. Then copy that record to the AssetMovements table using a query. So, the code will look something like this:
Dim OldLocation As String
Private Sub CmdSave_Click()
DoCmd.RunCommand acCmdSaveRecord
End Sub
Private Sub Form_AfterUpdate()
Dim strSQL
If OldLocation <> Location.Value Then
strSQL = "INSERT INTO AssetMovements SELECT T1.* FROM Assets WHERE Assets.ID = "
strSQL = strSQL & Me.ID
CurrentDb.Execute strSQL
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
OldLocation = Me.Location.OldValue
End Sub
Private Sub Form_Current()
OldLocation = Me.Location.Value
End Sub
This will then copy the current record of the form, using a unique ID (I guessed at AssetID), to the AssetMovement table.