form/vba date range setting for report

  • Thread starter Thread starter Laurie
  • Start date Start date
L

Laurie

I have set up a form for users to select criteria for
reports - including required date range. It works fine on
my machine (Win98 and Access 2002).

Transferred to an XP machine the code fails to select the
date range. Single stepping all looks well???

Can anyone help here?

' set up default dates on the form

Private Sub Form_Load()
today = Date
EndDate = CDate(today) 'default end of range
Mid$(today, 1, 2) = "01" 'default start of range
StartDate = CDate(today)
End Sub

' set up filter string
Private Sub OKbutton_Click()
SelectFilter = " [Students].[Date enrolled] > #" &
StartDate & "# And [Students].[Date enrolled]< #" &
EndDate & "# "

End Sub
 
It isn't good practice to handle dates as if they were strings. Use
DateSerial() if you want to change the year, month, or day of a date value.
For instance if you want the January date of Today, use:
Today = DateSerial(Year(Today), 1, Day(Today))
or
Today = DateAdd("m", Month(Today)-1, Today)
 
Back
Top