MS Access 找不到您的表达式中提到的字段组合框

MS Access cannot find the field combobox mentioned in youe expression

我正在尝试编写一段快速的 VBA 代码,用于检查 2 个组合框值是否在特定范围内匹配,如果匹配,应该 return 一条错误消息。

我发现我的代码在比较 cboOption1.Column(0)cboOption1.Column(0) 时失败了。所以我在额外的行中添加了 And Not Me.Controls("cboOption" & i) = Not Me.Controls("cboOption" & k) 以取消组合框对自身进行的任何比较。但现在我收到错误消息,指出 MS Access 无法找到我在该行的表达式中提到的字段组合框。知道出了什么问题吗?

Dim myArray As Variant
Dim x As Integer
myArray = Array(cboOption1.Column(0), cboOption2.Column(0), cboOption3.Column(0), cboOption4.Column(0))
For x = LBound(myArray) To UBound(myArray)
    For i = 1 To 4
        For j = 1 To 4
            If Me.Controls("cboOption" & i).Column(0) = myArray(x) _
                    And Me.Controls("cboOption" & j).Column(0) = myArray(x) _
                    And Not Me.Controls("cboOption" & i) = Not Me.Controls("cboOption" & k) Then
                 MsgBox "You cannot select " & myArray(x) & " twice."
                 Exit Sub
            End If
        Next
    Next
Next x

在进行值比较之前,如果 i = j 进行基本检查如何?

Dim myArray As Variant
Dim x As Integer
myArray = Array(cboOption1.Column(0), cboOption2.Column(0), cboOption3.Column(0), cboOption4.Column(0))

For x = LBound(myArray) To UBound(myArray)
    For i = 1 To 4
        For j = 1 To 4
            If i <> j Then
                If Me.Controls("cboOption" & i).Column(0) = myArray(x) _
                   And Me.Controls("cboOption" & j).Column(0) = myArray(x) Then
                    MsgBox "You cannot select " & myArray(x) & " twice."
                    Exit Sub
                End If
            End If
        Next
    Next
Next x