2015-01-09 5 views
0

특정 콤보 상자 값이 내 컨트롤 집합에서 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 
+0

'나는 높은 가치를 지니고있다'는 것을 의미합니까?이 값은 변수에 할당 되었습니까? 아니면 지역 변수에 할당되어 있습니까? w? ... –

+0

'MsgBox mdCount'에서 합리적인 범위 내에서 값을 얻지 못함 – methuselah

+0

[8 개의 콤보 상자에 null을 제외하고 서로 일치하는 값이 있는지 확인] (http://stackoverflow.com/ 질문/27851145/check-to-see-if-8-comboboxes-values-that-match-one-another-exclude-nul) –

답변

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 

귀하의 요구 사항은 없습니다 (

관련 문제