How to make a cascading combobox with multiple values? (1 Viewer)

cheberdy

Member
Local time
Today, 10:49
Joined
Mar 22, 2023
Messages
77
I have a form with two combo boxes where I set the start month in the first and the end month in the second. It then filters me all the months in between. I would like to have an additional combo box for all the days of the months that were previously selected. Can I do this with a query where I set a criterion? What would the criterion look like?
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:49
Joined
Sep 21, 2011
Messages
14,319
Month(datefield) >= than first combo and Month(datefield) <= second combo

Might need to include year, if you span across into the next/previous year?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:49
Joined
Oct 29, 2018
Messages
21,477
When you said all the "days," did you mean all the "dates?"
 

Josef P.

Well-known member
Local time
Today, 10:49
Joined
Feb 2, 2023
Messages
827
Code:
select ... from ... where DateField between dateserial(YearValue, [FirstMonth], 1) and dateserial(YearValue, [LastMonth] + 1, 0)
... enables the use of an index.
 

cheberdy

Member
Local time
Today, 10:49
Joined
Mar 22, 2023
Messages
77
Month(datefield) >= than first combo and Month(datefield) <= second combo

Might need to include year, if you span across into the next/previous year?
Code:
SELECT TimeSplit.Day, TimeSplit.Month
FROM TimeSplit
WHERE (((Timesplit.Month)=[Forms]![Timesort]!Month Between [cboStart] And [cboEnd]));
Timesplit is the source query. Timesort is the form and cboStart and cboEnd are the combo boxes. However, when I do it this way, it does not recognize cboStart and cboEnd.
 

Josef P.

Well-known member
Local time
Today, 10:49
Joined
Feb 2, 2023
Messages
827
Code:
SELECT TimeSplit.Day, TimeSplit.Month
FROM TimeSplit
WHERE Timesplit.Month Between [cboStart] And [cboEnd]
If the data source is used in a combobox in the same form with the 2 comboboxes, the form reference is not needed.
 

cheberdy

Member
Local time
Today, 10:49
Joined
Mar 22, 2023
Messages
77
Code:
SELECT TimeSplit.Day, TimeSplit.Month
FROM TimeSplit
WHERE Timesplit.Month Between [cboStart] And [cboEnd]
If the data source is used in a combobox in the same form with the 2 comboboxes, the form reference is not needed.
It still does not recognize the combo boxes
 

Josef P.

Well-known member
Local time
Today, 10:49
Joined
Feb 2, 2023
Messages
827
Do you execute Combobox.Requery after a value changed?
Code:
private sub cboStart_AfterUpdate()
    me.Your3rdComboxWithAboveSql.Requery
end Sub
private sub cboEnd_AfterUpdate()
    me.Your3rdComboxWithAboveSql.Requery
end Sub
 

Users who are viewing this thread

Top Bottom