【问题标题】:Check to see if combobox values matches more than two times检查组合框值是否匹配超过两次
【发布时间】:2015-03-07 06:23:39
【问题描述】:

如果特定组合框值在我的控件集中出现超过 3 次(“md”),我会尝试触发事件。然而,目前,尽管我的 Access 表单上只有 8 个组合框,但我仍不断获得 32 或 40 之类的高值。我做错了什么?

Dim mdCount As Integer
For Each ctl In Me.Controls
    If ctl.ControlType = acComboBox Then
        Set cmb = ctl
        If (currentDropDown.Value = cmb.Value) And (Not currentDropDown Is cmb) And (Not currentDropDown.Value = "md") Then
            MsgBox "You cannot select the same value twice."
        End If
        If (currentDropDown.Value = "md") Then
            mdCount = mdCount + 1
        End If
    End If
Next ctl
Set ctl = Nothing

Private Sub Submit_Click()
'MsgBox mdCount
If (mdCount > 2) Then 
    MsgBox "Error!"
    Exit Sub
End Sub

【问题讨论】:

标签: ms-access combobox vba ms-access-2010


【解决方案1】:

如果我对您的理解正确...尝试这样的事情(有点硬编码,但非常快):

Function CheckMatches() As Integer
Dim sTmp As String

sTmp = IIf(Nz(Me.Combo1.Value, "") = "md", ";", "") & _
        IIf(Nz(Me.Combo2.Value, "") = "md", ";", "") & _
        IIf(Nz(Me.Combo3.Value, "") = "md", ";", "")  'and so on...

CheckMatches = UBound(Split(sTmp, ";")) + 1
'+1 is necessary in case of Option Base 0, _
'because LBound(array) starts from 0

End Function

用法:

Private Sub Submit_Click()
Dim mdCount as Integer
mdCount = CheckMatches
If (mdCount > 2) Then 
    MsgBox "Error!"
    Exit Sub
End Sub

您的要求不清楚,所以我帮不上忙;(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多