Between Date Query from a Text Box

Hudas

Registered User.
Local time
Today, 14:18
Joined
May 13, 2013
Messages
55
Hello!

I have a form with two textbox , txtFrom and txtTo that is populated with a date from a date picker. What I'm hoping the query will is this:

1. When there is no entry on both txtFrom and txtTo it should show all records.
2. When there is no entry in txtFrom and there is entry in txtTo is should show all records prior to txtTo.
3. When there is an entry in txtFrom and there is no entry in txtTo it should show all records after txtTo.
4. When there is entry in txtFrom and txtTo it should show entry between the two dates.

Is this possible? Can anyone help me please...

Thank you
Hudas
 
Your form filter should be something like this:

Me.Filter="(myDate is null OR myDate>=#" & TxtFrom & "#) AND (myDate is null OR myDate<=#" &TxtTo & "#)"
Me.FilterOn=True

Note: TxtFrom and TxtTo need to be american format so if they are not substitute txtTo with Format(TxtTo,'mm/dd/yyyy')
 
Hi CJ_London,

Is it ok if I add this code even though I have a criteria in the query? Will there be a problem?

Thanks,Hudas
 
it should not be a problem - the query is your recordsource.

Best thing to do is to try it!

Just by way of note, if you manually filter your form using the access filtering options - it does so by populating me.filter
 

Users who are viewing this thread

Back
Top Bottom