update query unique index contain duplicate values

ss6857

Registered User.
Local time
Today, 11:17
Joined
Jul 12, 2011
Messages
38
Here is my code. I am getting a run time error that says "single row update/delete affected mroe than one row of a linked table. Unique index contains duplicate values" Error is in red. Any suggestions?

Code:
Private Sub Command108_Click()
Dim Cname As String
Dim Catname As String
Dim Cnum As Integer
Dim Catnum As Integer
Dim percent As Variant
Dim db As Database
Dim edate As Date
Dim pdfname As String
Dim vFilePath As String
Dim objname As String
Dim folderyear As Integer
'Dim edatetext As Variant
If IsNull(Me.Text126) Then
    MsgBox "Effective date field is empty.", vbOKOnly, "Effective Date"
    GoTo E
Else
End If
'===========================================================
'             Define variables
'===========================================================
percent = (Me.Text104 / 100) + 1
Debug.Print percent
Me.Combo113.SetFocus
Cname = Me.Combo113.Text
Debug.Print Cname
Me.Combo115.SetFocus
Catname = Me.Combo115.Text
Debug.Print Catname
Set db = CurrentDb
'===========================================================
'             Identify ID Numbes
'===========================================================
Cnum = DLookup("[PList_ID]", "dbo_tbl_Price_List", "[Description] = '" & Cname & "'")
Debug.Print Cnum
If IsNull(Me.Combo115) Then GoTo 0 Else
    Catnum = DLookup("[Category_ID]", "dbo_tbl_price_category", "[Category] = '" & Catname & "'")
    Debug.Print Catnum
    GoTo B:
'===========================================================
'             Update Query
'===========================================================
0:
'db.Execute ("UPDATE dbo_tbl_Pricing_Product_Level SET dbo_tbl_Pricing_Product_Level.Price = ([Price] * " & percent & ") WHERE dbo_tbl_Pricing_Product_Level.Price_ID = " & Cnum & "")
db.Execute ("UPDATE dbo_tbl_Pricing_Product_Level SET dbo_tbl_Pricing_Product_Level.Price = Round(20*([Price] * " & percent & "),0)/20, dbo_tbl_Pricing_Product_Level.UnitPrice = Round(20*([UnitPrice] * " & percent & "),0)/20 WHERE dbo_tbl_Pricing_Product_Level.Price_ID = " & Cnum & "")
B:
[COLOR=red]'db.Execute ("UPDATE dbo_tbl_Pricing_Product_Level SET dbo_tbl_Pricing_Product_Level.Price = ([Price] * " & percent & ") WHERE dbo_tbl_Pricing_Product_Level.Price_ID = " & Cnum & " AND dbo_tbl_Pricing_Product_Level.Category_ID = " & Catnum & "")
db.Execute ("UPDATE dbo_tbl_Pricing_Product_Level SET dbo_tbl_Pricing_Product_Level.Price = Round(20*([Price] * " & percent & "),0)/20, dbo_tbl_Pricing_Product_Level.UnitPrice = Round(20*([UnitPrice] * " & percent & "),0)/20 WHERE dbo_tbl_Pricing_Product_Level.Price_ID = " & Cnum & " AND dbo_tbl_Pricing_Product_Level.Category_ID = " & Catnum & "")[/COLOR]
 

Users who are viewing this thread

Back
Top Bottom