Jim,
Thanks for the response. But I am a novice learning as I go and copying a lot of already invented wheels. I found the above code as an example for filtering text. I can not find a sample with dates included. Please point me in the correct direction in more beginners terms. I check the link you included and can not figure out the correct way to apply it here.
Thanks
Dan
Invented wheels are great if they have something in them to guide you like commented code 'lots do not' and unfortunately lots of beginners copy and paste stuff without understanding what the code is actually doing and then carry on on adding to the pile until we have a magical plate of spaghetti. I'm not saying that is happening in your case because you are wanting to understand the actual process involved here... so lets examine what is happening.
A FOR NEXT loop consisting of only 2 iterations is more or less a waste of time It is easier to type two end if statements and refer to your controls explicitly. That having been said, the principle here (for me) is not so much to be 'method' critical or to organise the program flow essentially... it is in this particular case, a question of knowing what the SQL is that is being built on the fly as the posted code illustrates, in order that we can fully understand if the compiler can deal with the built SQL and execute it.
In short the posted code is looping and grabbing the field name from the tag property of the control it references and then grabbing the 'value' presented by the control concatenating (appending) this to a string and stripping the last 5 characters from that string and rather hoping it will work as a valid SQL statement.
Fact is it does/did/probably excellently on the first control .....BUT.....I dare say the original syntax was built around something that did not include date fields as part of any looping process.
You have grabbed the code innocently without knowing the extent of its interaction with the potential data it might be faced with. I suppose thats the bottom line explanation.
Date fields in Access are wrapped in delimiting characters namely the HASH mark (#) which is CHAR(35) in the ansii character set. The posted code shows char(34) which is quotation marks.
The hash mark is the standard delimiter for dates. This is where your syntax problem lies. Now other systems might not have so much trouble and (can be more forgiving in this 'date' area) but one has to appreciate and understand what Access expects. (If you were using SQL Server I might not be emphasising this so much, various systems have various tolerances... please understand me)
To fully explain the ins and outs would require a book and here I sit with me in danger of reinventing the wheel in that area too. Much of what is understood is already written one simply needs to know where to target that material in order to gain a fuller understanding.
Now I know that you are using Access 2007 from a previous post of yours and that Access 2007
now has report on 'click events' from which you can navigate to screen forms to conduct anything that you wish to do ie: filter a form or go to a form at a specific record... and so on.
I cannot unfortunately replicate fully what you have there (on this box) because I do not personally use Access 2007 and have no need to presently as my scoped need for corporately supporting it is minimal. Suffice it to say this... in order to help you I have attached a zip file that shows where you need to be on this. It should open in Access 2007 ok. I hope it explains it a little to you, but if not get back to me. :))
Don't be put off by the use of commands like TYPEOF or the useage of the listbox they are included merely to try and make my illustrative example fit 'your' code (and at the same time maybe give you an idea of differences in method with different control) as opposed to me writing the solution to this for you.
Remember I do not have exactly what you have there in front of you, so its all guesswork my end so to speak. If you break apart the code and go into help the command useages are fully explained.
Regards
Jim :)