In a combobox have dates
01/08/2021
15/06/2021
...
ecc...
i have myvardate=02/08/2021. i need to add in combobox only if not exists.
i need to loop the item in combobox, with a if condition, before to add myvardate, or exists a othre fast method?
add new item in combobox if...
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: add new item in combobox if...
Yes, you need to loop through the items of the combo box and compare them to the value of myvardate. If none matches, then use AddItem to add the new value.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36
Re: add new item in combobox if...
Wath you think about:
Private Sub AGG_GIORNO_CASSA(GIORNO)
With Me.CGIORNO1
For K = 1 To .ListCount - 1
If GIORNO = Split(.List(K), "-")(1) Then Exit For
Next K
If K = .ListCount - 1 Then
.AddItem UCase(Format(GIORNO, "DDD")) & "-" & GIORNO
End If
.Refresh
End With
'
End Sub
-
- Administrator
- Posts: 78391
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: add new item in combobox if...
The line
If K = .ListCount - 1 Then
should be
If K = .ListCount Then
If the loop runs to completion (Exit For is not executed), the loop index will be 1 more than the upper bound.
If K = .ListCount - 1 Then
should be
If K = .ListCount Then
If the loop runs to completion (Exit For is not executed), the loop index will be 1 more than the upper bound.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4343
- Joined: 26 Apr 2010, 17:36