Hi All
I have searched for a number of days and have not been able to find an answer to my question.
(out of courteously i will also point out i have posted this question on another board without however there has been no answer. i havent posted a link to the thread as i do not know the etiquette)
I have a form with multiple combo boxes on it. The combo boxes have the same list of data in them. The user can also type there own data into these combo boxes. I want to stop the user from being able to make the same selection in any of the multiple combo boxes. The combo boxes are created at run time and can vary in number.
So what I have done so far is added them to a class module and also a collection. I have added them to a class module so that i can utilize the change event. Once this change event fires it adds the combobox.value to another collection. It then cycles through all the results in the collection and checks that it hasn’t been duplicated. If it has it changes the .ControlTipText = "dup". My plan was then to check all the control tips before exiting the form for the tag "dup" and if it exists show a message to the user.
The code In the form module(setUpWizard) i have
code for class module called “FormControl”
My problem is that when I make the same selection in combobox no.2 as in combobox no.1. my code rightly adds the controltip “dup” to combobox no.2.
if I change combobox no.2 value then it removes the controltip however if I change combobox no.1 instead, combobox no.2 still keeps the controltip.
Any ideas how I can solve this problem?
I have searched for a number of days and have not been able to find an answer to my question.
(out of courteously i will also point out i have posted this question on another board without however there has been no answer. i havent posted a link to the thread as i do not know the etiquette)
I have a form with multiple combo boxes on it. The combo boxes have the same list of data in them. The user can also type there own data into these combo boxes. I want to stop the user from being able to make the same selection in any of the multiple combo boxes. The combo boxes are created at run time and can vary in number.
So what I have done so far is added them to a class module and also a collection. I have added them to a class module so that i can utilize the change event. Once this change event fires it adds the combobox.value to another collection. It then cycles through all the results in the collection and checks that it hasn’t been duplicated. If it has it changes the .ControlTipText = "dup". My plan was then to check all the control tips before exiting the form for the tag "dup" and if it exists show a message to the user.
The code In the form module(setUpWizard) i have
Code:
Dim BasisFeeName() As New FormControl
Private pCombo2boxes As New Collection
Public Property Get Combo2boxes() As Collection
Set Combo2boxes = pCombo2boxes
End Property
Private Sub CreatePage4()
Dim R As Integer, CtlCount4 As Integer
Dim NewCombo As msforms.ComboBox
Dim rCell As Range, rData As Range
With Worksheets("Fund Fees")
Set rData = Range(.Range("B1"), .Range("IV1").End(xlToLeft))
End With
CtlCount4 = 0
For R = 1 To 2
CtlCount4 = CtlCount4 + 1
Set NewCombo = Me.Controls.Add("Forms.ComboBox.1", "BasisFeeName" & R, True)
With NewCombo
.Top = (18 - 1) * (R - 1) + 18
.Left = 70
.Width = 78
.Height = 15
.Style = 0
End With
For Each rCell In rData
With rCell
If .MergeCells Then
If rCell.Value <> "" Then
NewCombo.AddItem rCell.Value
End If
End If
End With
Next
ReDim Preserve BasisFeeName(1 To CtlCount4)
Set BasisFeeName(CtlCount4).cBasisFeeName = NewCombo
BasisFeeName(CtlCount4).Combo2Name = NewCombo.Name
BasisFeeName(CtlCount4).SetCombo2Box NewCombo
pCombo2boxes.Add BasisFeeName(CtlCount4)
Next
End Sub
code for class module called “FormControl”
Code:
Public WithEvents cBasisFeeName As msforms.ComboBox
Private pCombo2Numbers As Collection
Private pCombo2Name As String
Public Property Let Combo2Name(Value As String)
pCombo2Name = Value
End Property
Public Property Get Combo2Name() As String
Combo2Name = pCombo2Name
End Property
Public Property Get Combo2Numbers() As Collection
Set Combo2Numbers = pCombo2Numbers
End Property
Public Sub SetCombo2Box(Value As msforms.ComboBox)
Set BasisFeeName = Value
End Sub
Private Sub cBasisFeeName_change()
Dim v As String, l As Long
With cBasisFeeName
If Len(.Text) = 0 Then
.ControlTipText = ""
Else
'store all the values in the comboboxs
Set pCombo2Numbers = New Collection
pCombo2Numbers.Add .Value
'check for duplicates
If Check2Values Then
.ControlTipText = "dup"
Else
.ControlTipText = ""
End If
End If
End With
End Sub
Private Function Check2Values() As Boolean
Dim n As Long, l As Long
For n = 1 To pCombo2Numbers.Count
For Each BasisFeeName In SetupWizard.Combo2boxes
If Not BasisFeeName.Combo2Numbers Is Nothing Then
For l = 1 To BasisFeeName.Combo2Numbers.Count
If BasisFeeName.Combo2Numbers(l) = pCombo2Numbers(n) Then
If Not (BasisFeeName.Combo2Name = pCombo2Name And l = n) Then
Check2Values = True
Exit Function
End If
End If
Next l
End If
Next BasisFeeName
Next n
End Function
My problem is that when I make the same selection in combobox no.2 as in combobox no.1. my code rightly adds the controltip “dup” to combobox no.2.
if I change combobox no.2 value then it removes the controltip however if I change combobox no.1 instead, combobox no.2 still keeps the controltip.
Any ideas how I can solve this problem?