Mit untenstehendem Code (Klassenmodul) wird verhindert, dass mit den 5 Comboboxen den gleichen Inhalt mehrmals ausgelesen werden kann. Bei Auswahl eines bereits vorhandenen Eintrages wird sofort eine Fehlermeldung ausgegeben.
Der Fehler ist nun, dass durch ComboBox.Change (weil das Dropdownfeld auf leer zurückgestellt wird) das Modul ein 2. Mal durchlaufen wird.
Kann ich dass irgendwie verhindern??
Private Sub combo(id As Integer, Nr As Integer)
On Error Resume Next
Select Case Nr
Case 1
If ComboBox2.ListIndex = id Then
MsgBox "Shit!"
ComboBox1.ListIndex = -1
Exit Sub
End If
If ComboBox3.ListIndex = id Then
MsgBox "Shit!"
ComboBox1.ListIndex = -1
Exit Sub
End If
If ComboBox4.ListIndex = id Then
MsgBox "Shit!"
ComboBox1.ListIndex = -1
Exit Sub
End If
If ComboBox5.ListIndex = id Then
MsgBox "Shit!"
ComboBox1.ListIndex = -1
Exit Sub
End If
Case 2
If ComboBox1.ListIndex = id Then
MsgBox "Shit!"
ComboBox2.ListIndex = -1
Exit Sub
End If
If ComboBox3.ListIndex = id Then
MsgBox "Shit!"
ComboBox2.ListIndex = -1
Exit Sub
End If
If ComboBox4.ListIndex = id Then
MsgBox "Shit!"
ComboBox2.ListIndex = -1
Exit Sub
End If
If ComboBox5.ListIndex = id Then
MsgBox "Shit!"
ComboBox2.ListIndex = -1
Exit Sub
End If
Case 3
If ComboBox1.ListIndex = id Then
MsgBox "Shit!"
ComboBox3.ListIndex = -1
Exit Sub
End If
If ComboBox2.ListIndex = id Then
MsgBox "Shit!"
ComboBox3.ListIndex = -1
Exit Sub
End If
If ComboBox4.ListIndex = id Then
MsgBox "Shit!"
ComboBox3.ListIndex = -1
Exit Sub
End If
If ComboBox5.ListIndex = id Then
MsgBox "Shit!"
ComboBox3.ListIndex = -1
Exit Sub
End If
Case 4
If ComboBox1.ListIndex = id Then
MsgBox "Shit!"
ComboBox4.ListIndex = -1
Exit Sub
End If
If ComboBox2.ListIndex = id Then
MsgBox "Shit!"
ComboBox4.ListIndex = -1
Exit Sub
End If
If ComboBox3.ListIndex = id Then
MsgBox "Shit!"
ComboBox4.ListIndex = -1
Exit Sub
End If
If ComboBox5.ListIndex = id Then
MsgBox "Shit!"
ComboBox4.ListIndex = -1
Exit Sub
End If
Case Else
If ComboBox1.ListIndex = id Then
MsgBox "Shit!"
ComboBox5.ListIndex = -1
Exit Sub
End If
If ComboBox2.ListIndex = id Then
MsgBox "Shit!"
ComboBox5.ListIndex = -1
Exit Sub
End If
If ComboBox3.ListIndex = id Then
MsgBox "Shit!"
ComboBox5.ListIndex = -1
Exit Sub
End If
If ComboBox4.ListIndex = id Then
MsgBox "Shit!"
ComboBox5.ListIndex = -1
Exit Sub
End If
End Select
End Sub
Private Sub ComboBox1_Change()
Dim id As Integer, Nr As Integer
id = ComboBox1.ListIndex
Nr = 1
Call combo(id, Nr)
End Sub
Private Sub ComboBox2_Change()
Dim id As Integer, Nr As Integer
id = ComboBox2.ListIndex
Nr = 2
Call combo(id, Nr)
End Sub
usw.. bis ComboBox5
Danke für eure Vorschläge