
Adding a new order overwrite the last row in the table
I have a table of order detail data comprising of 1 P.key, 3 F.keys and 1
Qty field. Using a data environment to make the connection and recordsets
etc, I have got the new order part working but it overwrites the last row in
the table when it saves the first record of the new order. I have shown my
code below, I hope it isn't to tricky to understand. If someone wanted to
show me how to batch save so each order is only written to the table when it
is complete, whether 1 record or 10 records long - I would be appreciative.
Also, a question, please. Is it compulsory that I have to provide the
AutoNumber for the table when I add the record like I have? I did it this
way because when I just wrote ...addnew I kept getting an error message
saying the aaction had been cancelled.
Thanks, here comes the code.
Chris
Private Sub cmdSaveItem_Click()
Dim autoVal, numVal, custVal, prodVal, qtyVal As Integer
If txtProdCode.Text = "" Or txtQtyItem.Text = "" Then
Exit Sub
End If
autoVal = Val(Label6.Caption)
numVal = txtOrdNum.Text
custVal = txtCustItem.Text
prodVal = txtProdCode.Text
qtyVal = txtQtyItem.Text
DE1.rsrsOrderItem.AddNew
DE1.rsrsOrderItem!OrderDetailID = autoVal
DE1.rsrsOrderItem!OrderNo = numVal
DE1.rsrsOrderItem!ProductCode = prodVal
DE1.rsrsOrderItem!Qty = qtyVal
DE1.rsrsOrderItem!CustID = custVal
DE1.rsrsOrderItem.Update
DE1.rsrsOrderItem.Requery
Label6.Caption = (autoVal + 1)
Label6.Refresh
txtOrdNum.Text = frmCustomer.txtOrdNo8.Text
txtCustItem.Text = frmCustomer.txtCustID1.Text
End Sub