I am working on a user form where you as part of the filtering process can enter a single year or an interval between two years.
I have three unbound fields
1- FindYearSpecific
2- FindYearStart
3- FindYearEnd
...and I am using the query builder cause I need to query other fields as well, so I would like to keep doing that instead of writing VBA (but that might be a mistake, I don't know...)
To find the specific year I have the following code:
Expand|Select|Wrap|Line Numbers
- Like[Forms]![frmSearchGeneral].[FindYearSpecific] & "*"
Then I have the following code for the year range:
Expand|Select|Wrap|Line Numbers
- Between IIf([Forms]![frmSearchGeneral].[FindYearStart] Is Null,#01-01-1000#,[Forms]![frmSearchGeneral].[FindYearStart]) And IIf([Forms]![frmSearchGeneral].[FindYearEnd] Is Null,#31-12-9999#,[Forms]![frmSearchGeneral].[FindYearEnd])
First of all, thank you, NeoPa, for helping with that code. I found it in an unrelated post.
In my top field in the query builder (Field) I have - FindYears: Year ([Date])
I use the extreme dates to make sure that I get all records if the field in the user form is left empty.
This works just fine most of the time. And I am not sure why it is only most of the time.
I have to write in both the fields before the code execute correctly. After that when I manually clears the fields everything works a cording to plan but if I use code to clear the fields like:
Expand|Select|Wrap|Line Numbers
- me.FindYearStart = ""
And on top of that, my real problem is, that I seem unable to combine the two criteria to get anything useful :S
Just to sum up:
I need a query that do the following
1- Checks if I am asking for a specific year
if Yes, then return all records for that year - Then nothing else
if No, continue to 2
2- Checks if I am asking for a year range
If FindYearStart is empty, then returns all records form the beginning of time until year entered in FindYearEnd.
If FindYearEnd is empty, then returns all records form FindYearStart to the end of time.
If there is a year in both fields, then returns the range asked for
I think I am almost there but I really need some help to get the rest of the way.
Thank you in advance and sorry for the wall of text.