Slightly OT: Need help with a criteria expression (Access) [Resolveed]
Hey,
I am designing a query using Access query builder. The criteria of the query is 2 dates coming from 2 text boxes on a form inside the DB.
this is the criteria that I have:
Between [Forms]![Reports_Form]![startDate].[text] And [Forms]![Reports_Form]![endDate].[text]
When I run this from the form the results are blank. Anyone know what I am doing wrong here?
PS: Posted this in the Database section with little help, figured I would try here.
Thanks
Re: Slightly OT: Need help with a criteria expression (Access)
I don't actually use the query builder, just the SQL view or buld it in code, but a couple possible things.
Do your textboxes have values? This means the form has to be open. You can't just build the query and run it like you could if you referred to actual values.
Second, and here I don't know about the query builder, are you querying correct data types? I'm guessing start_date & end_date are date fields in your table, but you're passing in strings from a textbox. You'd have to convert the strings to a date type, with # signs or CDate() - BETWEEN #Forms!Report_Forms...#. If you built your SQL in code, it would look something like this:
VB Code:
strSQL = "SELECT fldFoo FROM tblFoo WHERE fldDate BETWEEN #" & _
[Forms]![Reports_Form]![startDate].[text] & "# AND #" & _
[Forms]![Reports_Form]![endDate].[text] & "#"
If for some reason the date fields are actually text data types, the example I gave would replace the # signs with single quotes. But since they wouldn't then be actual dates, looking BETWEEN them would be pretty futile. Maybe it would do some ascii or binary comparison, but even if so, probably not the results you want.
Re: Slightly OT: Need help with a criteria expression (Access)
See your other thread in Databases Forum...
[edit]
Hmm Yeah forgot about the hashes, add those in too ;)