Question : MS Access Dates and Selecting a Range Between Two Dates in an Access Report

Hi All,

This is related to a previous question I asked, but perhaps in a simpler format with better information.

I am trying to generate an Access Report that uses a Date Filter and only displays results between two dates.  Here is my issue:

I am entering dates via a Form someone else created.  The Form uses an Input Mask so that if I enetr a date as, 01/08/2010, the Mask changes this date to: 1/8/2010.

My Report has a Date variable in it called 'TransDate and  this date is in the format of 01082010 (I can not change that either).

I need to filter/add a Report Filter for TransDate so that my report only displays data between a DATE1 and a DATE2, which represents my StartDate and EndDate.  I believe my Report Filter is not working because, let's say I enter via the Form a StartDate (DATE1) of 01082010 and an EndDate of 01092010, the Input Mask causes my Dates to be changed to: 1/8/2010 and 1/9/2010, Then I am trying to filter for TransDate (the Date on my Report) that is in the Format 01082010 and 01092010.

In my On Open Event in my Report, I have:

Private Sub Report_Open(Cancel As Integer)

Dim strFilter As String
Dim strDate1 As String, strDate2 As String
Dim mm As String, dd As String, yyyy As String


strDate1 = Forms!RunReports!DATE1
strDate2 = Forms!RunReports!DATE2

'For testing
MsgBox (strDate1)
MsgBox (strDate2)

'Not sure if my Syntax is correct in next line - ???
strFilter = "TransDate between " & "#" & strDate1 & "#" & " And " & "#" & strDate2 & "#"

MsgBox (strFilter)

End Sub

When I message box my str Filter, the Filter is:

TransDate between #1/8/2010# And #1/9/2010#

which looks OK to me, but I think the Filter is NOT WORKING because the dates in my Report are of the Format 01082010 and 01092010

I am Not sure if this is my problem and - if so - how do I get the dates in the form of 1/8/2010 into the form of 01082010 so they match the format of the dates in my Report (assuming this is my problem).

Thanks!

Answer : MS Access Dates and Selecting a Range Between Two Dates in an Access Report



Actually, you should change the date format in BOTH criteria and report to YYYYMMDD.  That way you will ensure a 'range match' by matching text fields.


In your report source query- add a column and 'arrange' the text in your 'date' field to YYYYMMDD.
On your report - create an invisible textbox and bind to this new query column.

In the OPEN REPORT code...

dim vd1 as string
dim vd2 as string
vd1 = format(me.date1,"YYYYMMDD")
vd2 = format(me.date2, "YYYYMMDD")
CRIT = "[YourInvisibleField]>=" & chr(34) & vd1 & chr(34) & " and [YourInvisibleField] <=" & chr(34) & vd2 & chr(34)
 note: chr(34) = quotes - use these since you're comparing text fields.

Scott C



Random Solutions  
 
programming4us programming4us