fill combo to other combo

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

fill combo to other combo

Post by sal21 »

in combobox1 have:

01/01/2014
15/12/2015
24/03/2016
...
17/11/2017
01/05/2022

if i click on 15/12/2015 from combobox1 i need to fill combobox2 with dates in combobox1 > 15/12/2015

i my case, in combobox2:

24/03/2016
...
17/11/2017
01/05/2022

if i click on 17/11/2017 from combobox1 i need to fill combobox2 with dates in combobox1 > 17/11/2017

i my case, in combobox2:

01/05/2022

note:
the date in combobox1 are just sorted.
naturally n combobox1 contain one date fill combobox2 with the date of combobox1

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill combo to other combo

Post by HansV »

Try this:

Code: Select all

Private Sub ComboBox1_AfterUpdate()
    Dim i As Long
    Me.ComboBox2.Clear
    If Me.ComboBox1.ListIndex >= 0 Then
        For i = Me.ComboBox1.ListIndex + 1 To Me.ComboBox1.ListCount - 1
            Me.ComboBox2.AddItem Me.ComboBox1.List(i)
        Next i
    End If
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: fill combo to other combo

Post by sal21 »

HansV wrote:
29 Apr 2021, 07:22
Try this:

Code: Select all

Private Sub ComboBox1_AfterUpdate()
    Dim i As Long
    Me.ComboBox2.Clear
    If Me.ComboBox1.ListIndex >= 0 Then
        For i = Me.ComboBox1.ListIndex + 1 To Me.ComboBox1.ListCount - 1
            Me.ComboBox2.AddItem Me.ComboBox1.List(i)
        Next i
    End If
End Sub
SORRY... but i have see my project, with attention...

i need to use this code as public function....

in my case (old combobox1) is named CINIZIO, and the (old combobox2) is named CFINE, In this case ai need to pass the two combobox name to a function.

Sorry bro.

to understand me, my start code:

Code: Select all

Public Sub FILL_SUB_COMBO(CMB0 As ComboBox, CMB1 As ComboBox)
    Dim C As Integer
    CMB0.Clear
    If CMB0.ListIndex >= 0 Then
        For C = CMB0.ListIndex + 1 To CMB0.ListCount - 1
            CMB1.AddItem CMB0.List(C)
        Next C
    End If    
End Sub

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill combo to other combo

Post by HansV »

Change CMB0.Clear to CMB1.Clear
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: fill combo to other combo

Post by sal21 »

HansV wrote:
29 Apr 2021, 09:56
Change CMB0.Clear to CMB1.Clear
tks!
MY MIND IS IN FIRE :grin:

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: fill combo to other combo

Post by sal21 »

HansV wrote:
29 Apr 2021, 07:22
Try this:

Code: Select all

Private Sub ComboBox1_AfterUpdate()
    Dim i As Long
    Me.ComboBox2.Clear
    If Me.ComboBox1.ListIndex >= 0 Then
        For i = Me.ComboBox1.ListIndex + 1 To Me.ComboBox1.ListCount - 1
            Me.ComboBox2.AddItem Me.ComboBox1.List(i)
        Next i
    End If
End Sub
How to fill also the combobox1 have only one item, sorry for my error.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill combo to other combo

Post by HansV »

Does this do what you want?

Code: Select all

Private Sub ComboBox1_AfterUpdate()
    Dim i As Long
    Me.ComboBox2.Clear
    If Me.ComboBox1.ListIndex >= 0 Then
        If Me.ComboBox.ListCount = 1 Then
            Me.ComboBox2.AddItem Me.ComboBox1.List(0)
        Else
            For i = Me.ComboBox1.ListIndex + 1 To Me.ComboBox1.ListCount - 1
                Me.ComboBox2.AddItem Me.ComboBox1.List(i)
            Next i
        End If
    End If
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: fill combo to other combo

Post by sal21 »

HansV wrote:
30 Apr 2021, 19:03
Does this do what you want?

Code: Select all

Private Sub ComboBox1_AfterUpdate()
    Dim i As Long
    Me.ComboBox2.Clear
    If Me.ComboBox1.ListIndex >= 0 Then
        If Me.ComboBox.ListCount = 1 Then
            Me.ComboBox2.AddItem Me.ComboBox1.List(0)
        Else
            For i = Me.ComboBox1.ListIndex + 1 To Me.ComboBox1.ListCount - 1
                Me.ComboBox2.AddItem Me.ComboBox1.List(i)
            Next i
        End If
    End If
End Sub
EXACTLY THIS!
Tks.