Hi can anyone help me please???
I have a button that when pressed copies some fields from one table to another. However if when these details are changed on the form, if this button is clicked, i get an error saying that this record cannot be copied as it is a duplicate of a primary key value.
I want to write soem code so that the record will either be created or will be edited if that primary key value is already existent!
A VB programmer (not in access though) told me to use a if statement. Yet on these forums someone told me to try dlookup function.
I am really confused as to where to look to solve this problem.. can anyone give me some advice?
this is my present code.
Private Sub Command20_Click()
Dim rsLicense As Recordset
Dim rsOrderDetails As Recordset
Dim rsOrders As Recordset
'
Dim sDetailID As String
'
Set rsOrderDetails = Application.CurrentDb.OpenRecordset("order details", dbOpenDynaset, dbPessimistic)
Set rsLicense = Application.CurrentDb.OpenRecordset("License")
Set rsOrders = Application.CurrentDb.OpenRecordset("Orders")
'
rsOrderDetails.MoveLast
rsOrderDetails.MoveFirst
'
sDetailID = Me.DetailID
rsOrderDetails.FindFirst ("DetailID = " & sDetailID)
rsLicense.AddNew
'
rsLicense("DetailID") = rsOrderDetails("DetailID")
'
rsLicense("73 Serial No") = rsOrderDetails("SerialNO")
'
rsLicense("Product Name") = rsOrderDetails("ProductID")
'
rsLicense("AMP Renewal Date") = rsOrderDetails("RenewalDate")
'
rsLicense("End-User") = rsOrders("EndUser")
'
rsLicense("Reseller") = rsOrders("Re-Seller")
'
rsLicense("Location") = rsOrders("ShipCity")
'
rsLicense.Update
'
rsOrderDetails.CLOSE
rsLicense.CLOSE
'
End Sub
any ideas would be greatly appreciated!
thanks
Sarah
I have a button that when pressed copies some fields from one table to another. However if when these details are changed on the form, if this button is clicked, i get an error saying that this record cannot be copied as it is a duplicate of a primary key value.
I want to write soem code so that the record will either be created or will be edited if that primary key value is already existent!
A VB programmer (not in access though) told me to use a if statement. Yet on these forums someone told me to try dlookup function.
I am really confused as to where to look to solve this problem.. can anyone give me some advice?
this is my present code.
Private Sub Command20_Click()
Dim rsLicense As Recordset
Dim rsOrderDetails As Recordset
Dim rsOrders As Recordset
'
Dim sDetailID As String
'
Set rsOrderDetails = Application.CurrentDb.OpenRecordset("order details", dbOpenDynaset, dbPessimistic)
Set rsLicense = Application.CurrentDb.OpenRecordset("License")
Set rsOrders = Application.CurrentDb.OpenRecordset("Orders")
'
rsOrderDetails.MoveLast
rsOrderDetails.MoveFirst
'
sDetailID = Me.DetailID
rsOrderDetails.FindFirst ("DetailID = " & sDetailID)
rsLicense.AddNew
'
rsLicense("DetailID") = rsOrderDetails("DetailID")
'
rsLicense("73 Serial No") = rsOrderDetails("SerialNO")
'
rsLicense("Product Name") = rsOrderDetails("ProductID")
'
rsLicense("AMP Renewal Date") = rsOrderDetails("RenewalDate")
'
rsLicense("End-User") = rsOrders("EndUser")
'
rsLicense("Reseller") = rsOrders("Re-Seller")
'
rsLicense("Location") = rsOrders("ShipCity")
'
rsLicense.Update
'
rsOrderDetails.CLOSE
rsLicense.CLOSE
'
End Sub
any ideas would be greatly appreciated!
thanks
Sarah