1

我已经为此工作了 2 天。基本上我有 2 个列表框,我想要一个命令按钮来比较值并显示不匹配的值(那些出现在第一个列表框中但不在第二个列表框中的值)并将它们列出在第三个列表框中。我不确定这是否是最好的方法,但这是我的代码。它与以下消息一致:

参数数量错误或属性分配无效

我的列表框被命名为 CompList1、CompList2 和 CompList3。

Dim BoolAdd As Boolean, I As Long, j As Long
'Set initial Flag
BoolAdd = True
'If CompList2 is empty then abort operation
If CompList2.ListCount = 0 Then
MsgBox "Nothing to compare"
Exit Sub
'If CompList1 is empty then copy entire CompList2 to CompList3
ElseIf CompList1.ListCount = 0 Then
For I = 0 To CompList2.ListCount
CompList3.AddItem CompList2.Value
Next I
Else
For I = CompList2.ListCount - 1 To 0 Step -1
For j = 0 To CompList1.ListCount
If CompList2.ListCount(I) = CompList1.ListCount(j) Then
'If match found then abort
BoolAdd = False
Exit For
End If
DoEvents
Next j
'If not found then add to CompList3
If BoolAdd = True Then CompList3.AddItem CompList2.Value
DoEvents
Next I
End If
4

1 回答 1

0

一些注意事项:

Dim tdf1 As TableDef
Dim tdf2 As TableDef
Dim db As Database

Set db = CurrentDb

Set tdf1 = db.TableDefs(Me.CompList1.RowSource)
For Each fld In tdf1.Fields
    sFields = sFields & ";" & fld.Name
Next

sFields = sFields & ";"

Set tdf2 = db.TableDefs(Me.CompList2.RowSource)
For Each fld In tdf2.Fields
    sf = ";" & fld.Name & ";"
    sFields = Replace(sFields, sf, ";")
Next

Me.CompList3.RowSource = Mid(sFields,2)

编辑:

字段列表,组合属性

于 2012-07-26T20:06:49.330 回答