Between Dates selector

Lost Paul
StarLounger
Posts: 93
Joined: 10 Oct 2019, 09:43

Between Dates selector

Post by Lost Paul »

Hi,

Been away from Access for nearly 10 years and have forgotten so much.

But I'll start with a (user) form used to provide criteria to a query.

The issues began with the ComboBoxes;
I wanted to have the default value at either "*" or 01/01/2020 (for the [FromDate] combobox), to bring all records (at least before the 2nd combobox [ToDate]).
I could only get errors, or default date became 30/12/1989.

In the query, I couldn't seem to get between to work either; would either result in zero records found or resulted in an error.
Used the following as the 'from'; Like [forms]![FrmCERselector]![FromDate] & "*"

Any help would be very welcome
TIA

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Between Dates selector

Post by HansV »

What is the row source of the FromDate and ToDate combo boxes?
Best wishes,
Hans

Lost Paul
StarLounger
Posts: 93
Joined: 10 Oct 2019, 09:43

Re: Between Dates selector

Post by Lost Paul »

Both FromDate & ToDate;

SELECT Tbl_Log.Act_date
FROM Tbl_Log
GROUP BY Tbl_Log.Hearing_date;

User avatar
HansV
Administrator
Posts: 78475
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Between Dates selector

Post by HansV »

You could add 1/1/1900 and 31/12/2099 to the Act_Date field, and set the default value for FromDate to #1/1/1900# and that for ToDate to #31/12/2099# (you must add # around literal date values).
Best wishes,
Hans

Lost Paul
StarLounger
Posts: 93
Joined: 10 Oct 2019, 09:43

Re: Between Dates selector

Post by Lost Paul »

I've managed (sort of) with the following in the query;

SELECT TestData.ID, TestData.Day_entered, TestData.Location, TestData.ActDate, TestData.Who, Year([Actdate]) AS Yr, Month([Actdate]) AS Mnth
FROM TestData
WHERE (((TestData.Location) Like [forms]![FrmCERselector]![LocSel]) AND ((TestData.ActDate)>[Forms]![FrmCERselector]![FromDate]-1 And (TestData.ActDate)<[Forms]![FrmCERselector]![ToDate]+1))
ORDER BY TestData.ActDate;


Though, I'm sure there must be a better way.

Lost Paul
StarLounger
Posts: 93
Joined: 10 Oct 2019, 09:43

Re: Between Dates selector

Post by Lost Paul »

RE; default values.

#01/01/1900# works. Stangely, other dates not so much.
But #31/12/2099# also does.

And works as hoped - thank you