View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Malcolm Makin[_2_] Malcolm Makin[_2_] is offline
external usenet poster
 
Posts: 5
Default Query on Date range does not qualify the Year

My data source is another Excel workbook. The dates were entered by default
as m/d/yyyy. I have then set the explicit format on the cells to be
mm/dd/yyyy. However, the query pulls data regardless of year. Like I
metioned before, the Month/Day range is correct, just not the year. I have
also tried the #mm/dd/yyyy method in my query, but it does not help.

"K Dales" wrote:

Looks like what you are getting is an alpha sort based on the text string,
not a date sort based on date values. The way to fix it depends on your data
source/SQL interpreter; you may need to put #mm/dd/yy# or else leave the
dates in their native numeric format.

"Malcolm Makin" wrote:

I have a query that pulls data based on a date range. The data that comes
out is correct based on the Month and Day values, however the year seems to
not factor into the query. For instance, I am looking at dates from years
2005 and 2004. If my query looks for 06/01/2005 thru 07/01/2005, I receive
results from 06/01 thru 07/01 from both 2004 and 2005.

Here is what my query looks like:

BeginDate = Format(Date, "mm/dd/yyyy")
EndDate = Format(DateAdd("d", 14, BeginDate), "mm/dd/yyyy")

SQL = "SELECT reqdate, Customer FROM [detail$] WHERE (reqdate = '" & _
BeginDate & "') AND (reqdate <= '" & EndDate & "') ORDER BY reqdate"