我在Access中有一个表,其中显示了产品及其相关代码。每个产品都应该有一个代码,但是有时用户会犯一个错误,并将相同的代码提供给两个不同的产品。我称之为“复制错误”
在某种程度上,一切正常。上面提到的表的字段是: 名称,提示,IdProvider,价格,CodeBar。对我们来说唯一重要的两个是Name和CodeBar。
为防止出现重复错误结果,但又提供了保留重复代码的机会,我添加了一个警告用户此问题的按钮。这是该按钮的代码。
Dim Magazine As Database
Dim Verification As Recordset
Dim CodProd As Recordset
Dim n As Integer
Dim way As String
Dim List As String
Dim SQL2 As String
Dim SQL As String
Dim CodProduct As String
Dim NameBarrasDuplicado As String
Set Magazine = CurrentDb
SQL = " SELECT Warehouse.CodeBar FROM Warehouse GROUP BY Warehouse.CodeBar HAVING (((Count(Warehouse.[CodeBar]))>1))"
Set Verification = Magazine.OpenRecordset(SQL, dbOpenDynaset)
If (Verification.RecordCount > 0) Then
SQL2 = "SELECT Warehouse.Name FROM Warehouse WHERE Warehouse.CodeBar = '" & Verification.Fields(0) & " ' "
Set CodProd = Magazine.OpenRecordset(SQL2, dbOpenDynaset)
CodProd.MoveFirst
Do Until Verification.EOF
Do Until CodProd.EOF
CodProduct = CodProd.Fields(0) & ", " & CodProducto & ""
MsgBox (CodProduct)
CodProd.MoveNext
Loop
CodProd.MoveFirst
List = List & ", " & Verification.Fields(0)
Verification.MoveNext
Loop
MsgBox ("Warehouse duplicated products are: " & CodProduct & " for these Barcodes : " & List & ".")
Else
MsgBox ("Everything OK, no duplicated codes found")
End If
结束子
不幸的是,前面提到的算法的结果是这样的:
结果错误。它不会显示共享重复条形码的产品的名称,而是显示相同的名称,而与条形码无关。我想指出的是,重复的条形码是可以的。但是该程序在要显示具有这些重复代码的产品名称时失败。
任何人都可以对此提供线索吗?是什么使第二个记录集仅保存两个产品名称而不是一个?