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
fill combo to other combo
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: fill combo to other combo
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
Hans
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
Re: fill combo to other combo
SORRY... but i have see my project, with attention...HansV wrote: ↑29 Apr 2021, 07:22Try 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
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
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
Re: fill combo to other combo
How to fill also the combobox1 have only one item, sorry for my error.HansV wrote: ↑29 Apr 2021, 07:22Try 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
-
- Administrator
- Posts: 78236
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: fill combo to other combo
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
Hans
-
- PlatinumLounger
- Posts: 4334
- Joined: 26 Apr 2010, 17:36
Re: fill combo to other combo
EXACTLY THIS!HansV wrote: ↑30 Apr 2021, 19:03Does 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
Tks.