I hope this code will help you:
It runs through the datagrid and collects first the unique dates in an array.
Once all the unique dates found, it add s them to the comboboxes.
- Private Sub Command1_Click()
-
Dim ARRREC() As String
-
Dim ARRRECidx As Integer
-
Dim RECSET As ADODB.Recordset
-
Dim RECSETdate As String
-
Dim PRESENT As Boolean
-
Set RECSET = DataEnvironment1.rsCommand1 '§ connect the recordset to the database
-
ReDim ARRREC(0)
-
'§ put unique dates in the array
-
With RECSET
-
Do Until .EOF
-
RECSETdate = .Fields(0)
-
PRESENT = False
-
'§ check array if retreved date exist in array
-
For ARRRECidx = 0 To UBound(ARRREC)
-
If RECSETdate = ARRREC(ARRRECidx) Then PRESENT = True
-
Next
-
'§ if not present: add
-
If PRESENT = False Then
-
ReDim Preserve ARRREC(UBound(ARRREC) + 1)
-
ARRREC(UBound(ARRREC)) = RECSETdate
-
End If
-
.MoveNext '§ go to next row
-
Loop
-
.MoveFirst '§ go back to top of list
-
End With
-
With frmComboBox
-
'§ dump array in the comboboxes
-
For ARRRECidx = 1 To UBound(ARRREC)
-
.cboFromDate.AddItem ARRREC(ARRRECidx)
-
.cboToDate.AddItem ARRREC(ARRRECidx)
-
Next
-
.Show
-
End With
-
Set RECSET = Nothing '§ clean memory
-
Me.Hide
-
End Sub
PS:
it's better to collect the unique dates then to connect to the database and put all the dates in the combobox because the dates are more than once in the records.