I have a form which allows the user add a record to a table but when the Create Operation button is clicked two records are added to the table instead of one. When I add a second the extra record is then changed to the newest record added. This continues to happen and there is always 1 extra record in my table. How would I go about changing this ?
Here is the code I am using to add the record :
Private Sub Save_Operation_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
strElement = Me.Element.Value
strOperation = Me.Operation.Value
strProduct = Me.Product_ID.Value
strTime = Me.Time.Value
strQty = Me.Qty.Value
Set db = CurrentDb
Set rs = db.OpenRecordset("Labour", dbOpenTable)
rs.AddNew
rs("Element").Value = strElement
rs("Operation").Value = strOperation
rs("Product_ID").Value = strProduct
rs("Time").Value = strTime
rs("Qty").Value = strQty
rs.Update
i think the problem is the use of "addnew" so try this :
With rs
.AddNew
!Element = strElement
!Operation = strOperation
!Product_ID = strProduct
!Time = strTime
!Qty = strQty
.Update
End With