检查组合框值是否匹配超过两次
Check to see if combobox values matches more than two times
如果特定组合框值在我的控件集中出现超过 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
如果我理解正确的话...尝试这样的事情(有点硬编码,但非常快):
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
您的要求不明确,帮不上忙了;(
如果特定组合框值在我的控件集中出现超过 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
如果我理解正确的话...尝试这样的事情(有点硬编码,但非常快):
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
您的要求不明确,帮不上忙了;(