Hi Ron,
Am 19.04.2018 um 14:25 schrieb Ron Paii:
> On Wednesday, April 18, 2018 at 10:03:55 PM UTC-5, Patrick Finucane wrote:
>> On Wednesday, April 18, 2018 at 10:06:33 PM UTC-4,
rwpear...@gmail.com wrote:
>>> I have been trying to pass a date/s to sql but to no avail.
>>>
>>> The start and end dates are in the tblConfiguration and I've tried using DLookup as shown below......no workie!!
>>>
>>> What am I doing wrong????
>>>
>>> Dim StartDate As String
>>> Dim EndDate As String
>>>
>>> StartDate = DLookup("[YearBegins]", "[tblConfiguration]")
>>> EndDate = DLookup("[YearEnds]", "[tblConfiguration]")
>>>
>>>
Since dlookup returns a variant type, the data type should also be
defined like this, instead of using a string type, otherwise problems
with nulls may occur.
>>> Me.RecordSource = "SELECT * FROM tblIncome where [tblIncome].[TransactionDate] Between StartDate and EndDate"
>>>
>>> TIA4
>> You put date variables in #'s. Startdate/Enddate are variables. not part of the SQL string. So between #" & StartDate & "# And #" & EndDate & "#" would work better.
> Expanding on Patrick's post
>
> "between and" is short hand for "[TransactionDate] >= datestart and [TransactionDate] < dateend"
please note that the upper operator is "less or equal" not simple
"less". This is something different.
> Since date columns can include time if [TransactionDate] values includes time; the query will not return transactions on the end date and may miss some on the start date. you should do the following
that's the point
> between #" & datevalue(startdate) & "# and #" & datevalue(dateadd("d",1, enddate) & "# "
and to take this into account the easiest way is to compare only the
date part like "where DateValue([Transactiondate]) between #" &
startdate & "# and #" & enddate "# "
see also
http://www.vb123.com.au/200309_ds_aa.htm for some other useful
tips using dates in access databases.
Ulrich