Reputation: 1
Hi i am using vb6 ms access backend, instead of updating a record it duplicates and creates a new entry. my table does not use primary key due to the relationship with other tables. How can i make it update a record and not duplicate here is my code
Private Sub cmdSave_Click()
With Connect.rsitem
.Open , , adOpenDynamic, adLockOptimistic
If EditItem = False Then .AddNew
!itemno = txtItemNo.Text
!desc1 = txtDesc1.Text
!desc2 = txtDesc2.Text
!onhandqty = txtOnhandQty.Text
!unitprice = txtUnitPrice.Text
!Size = txtSize.Text
!upc = txtupc.Text
!Ordercost = txtOrderCost.Text
.Update
.Close
End sub
Upvotes: 0
Views: 718
Reputation: 5719
Do select query first ..
Dim rs As DAO.Recordset
rs.Open "SELECT * FROM mytable WHERE itemno = '" & txtItemNo.Text & "'"
If Not rs.BOF and Not rs.EOF then
'save the record ......
End If
If rs.State = adStateOpen Then rs.Close
Set rs = Nothing
Upvotes: 1