Private Sub Form_Close()
Dim sSQL, stringSQL As String
Dim rst As DAO.Recordset
sSQL = "SELECT BarCode, [Goods Name] FROM tblInventory WHERE BarCode='" & Me.ID & "'"
Set rst = CurrentDb.OpenRecordset(sSQL)
If rst.EOF Then
stringSQL = "INSERT INTO tblInventory(BarCode,[Goods Name],Unit,[Unit Price],[Initial Stock],[Current Stock],[Exit Item]) values('" & Me.ID & "','" & Me.Description & "','" & Me.Unit & "'," & Replace(Format(Me.Price, "0.00"), ",", ".") & "," & Me.Amount & "," & Me.Amount & ",0)"
DoCmd.SetWarnings False
DoCmd.RunSQL (stringSQL)
DoCmd.SetWarnings True
Else
stringSQL = "UPDATE tblInventory SET [Current Stock]=[Current Stock]+" & Me.Amount & " WHERE BarCode='" & Me.ID & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL (stringSQL) // the error is at this location//
DoCmd.SetWarnings True
End If
rst.Close
End Sub
Private Sub ID_AfterUpdate()
Dim sSQL As String
Dim rst As DAO.Recordset
sSQL = "SELECT BarCode, [Goods Name], Unit, [Unit Price] FROM tblInventory WHERE BarCode='" & Me.ID & "'"
Set rst = CurrentDb.OpenRecordset(sSQL)
If rst.EOF Then
MsgBox "New Parts"
Me.Description.SetFocus
Else
Me.Description = rst(1).Value
Me.Unit = rst(2).Value
Me.Price = rst(3).Value
Me.Amount.SetFocus
End If
rst.Close
End Sub
What I have tried:
I have also noticed that if i only add 1 item it works. but does not allow another item to be input to the table. I have to close the form before it will add another item. This is an access data base i am using in access 2010, it is being developed to track inventory. I have a table that gets incoming inventory the jave takes the incoming and moves it to a table called tblinventory when i enter new item it does what it is supposed to do. however if i try to enter another item that item does not make it to the tblinventory it does show on tblincoming. I also noticed that if i change my mind and close the input form for incoming i get an error 3134, the form is empty at this time.I tried to modify the code but them get error after entering every item. so went back to the initial error. when i debug it show the on the line DoCmd.RunSql (stringSQL) I have commented the line in the code.