As Rick says referencing controls on an unbound dialogue form is a much
better approach to this sort of problem. I would normally use two combo
boxes on the form, one which lists all the years over a range, e.g. 2000 to
2020, the other which list the months. I'd normally have the combo box show
the month names but have a value of the number by using a value list like so
as its RowSource:
1;January;2;February;3;March;4;April;5;May;6;June;7;July;8;August;9;September;10;October;11;November;12;December
and setting the combo box's BoundColumn property to 1, its ColumnCount to 2
and its ColumnWidths to 0;8cm (or rough equivalent in inches, but the first
dimension must be zero to hide the month numbers). Add a button to the form
to open the query or better still a form or report based on the query.
In the query you can then use the Year and Month functions to restrict the
result to the selected months, e.g.
SELECT *
FROM Orders
WHERE YEAR(OrderDate) = Forms!frmOrdersDlg!cboYear
AND MONTH(OrderDate) = Forms!frmOrdersDlg!cboMonth;
where frmOrdersDlg is the name of the form and cboYear and cboMonth are the
names of the two combo boxes.
Ken Sheridan
Stafford, England