accessonly11
Member
- Local time
- Today, 13:35
- Joined
- Aug 20, 2022
- Messages
- 91
hi members,
i want to duplicate form and its subform record where invoice number matched, but
i am facing an error 3201, you cannot add or change a record because a related record is required in table tblcustomer.....
while this code
got highlighted yellow.
my code behind click button is as under
any suggestions please,
please tell me for further info about my db
i want to duplicate form and its subform record where invoice number matched, but
i am facing an error 3201, you cannot add or change a record because a related record is required in table tblcustomer.....
while this code
Code:
rstSale.Update
my code behind click button is as under
Code:
Private Sub cmdLoad_Click()
Dim strSql As String
Dim rstSale As Recordset
Dim rstSaleDetails As Recordset
Dim lngNewSaleID As Long
'Get the invoice number from the text box
Dim strInvoiceNo As Long
strInvoiceNo = Me.InvoiceNo.Value
'Get the existing record for that particular invoice from the Saledata (main table)
strSql = "Select * From tblSale where SINo = " & strInvoiceNo & ""
Set rstSale = CurrentDb.OpenRecordset(strSql)
'Create a new record in the tblSale table with the same data as the existing record
rstSale.AddNew
rstSale("SINo").Value = rstSale("SINo")
rstSale("CustomerID").Value = rstSale("CustomerID")
rstSale("PatientName").Value = rstSale("PatientName")
rstSale("DateTime").Value = rstSale("DateTime")
rstSale("SaleStatus").Value = rstSale("SaleStatus")
rstSale("TRetail").Value = rstSale("TRetail")
rstSale("TDiscount").Value = rstSale("TDiscount")
rstSale("TSale").Value = rstSale("TSale")
rstSale("CashReceived").Value = rstSale("CashReceived")
rstSale("IsPaid").Value = rstSale("IsPaid")
rstSale("DateSettle").Value = rstSale("DateSettle")
rstSale("CreatedBy").Value = rstSale("CreatedBy")
rstSale.Update
lngNewSaleID = rstSale("SaleID").Value
'Get the Sale Details for the existing invoice
strSql = "SELECT * FROM tblSaleDetails where SaleID = " & rstSale("SaleID")
Set rstSaleDetails = CurrentDb.OpenRecordset(strSql)
'Create new sale detail records for the new invoice
rstSaleDetails.MoveFirst
Do Until rstSaleDetails.EOF
rstSaleDetails.AddNew
rstSaleDetails("SaleID").Value = lngNewSaleID
rstSaleDetails("ProductID").Value = rstSaleDetails("ProductID")
rstSaleDetails("Qty").Value = rstSaleDetails("Qty")
rstSaleDetails("Retail").Value = rstSaleDetails("Retail")
rstSaleDetails("Discount").Value = rstSaleDetails("Discount")
rstSaleDetails("Sale").Value = rstSaleDetails("Sale")
rstSaleDetails("TRetail").Value = rstSaleDetails("TRetail")
rstSaleDetails("TDiscount").Value = rstSaleDetails("TDiscount")
rstSaleDetails("TSale").Value = rstSaleDetails("TSale")
rstSaleDetails.Update
rstSaleDetails.MoveNext
Loop
'Refresh the main form and subform to show the new record
Me.Refresh
Me.frmSaleDetails1.Form.Refresh
End Sub
any suggestions please,
please tell me for further info about my db