Selecting rows by date

Jim Stanicki

Registered User.
Local time
Today, 10:31
Joined
Aug 7, 2007
Messages
36
I am not yet comfortable with date compares. Would someone please tell me how this should be done? I present a form asking for start and end date and want to restrict report data to that date range.
Thanks
Jim

Private Sub Report_Open(Cancel As Integer)

Dim dteStart As Date
Dim dteEnd As Date

DoCmd.OpenForm "AskDates", windowMode:=acDialog

dteStart = Forms("AskDates")!txtStartDate
dteEnd = Forms("AskDates")!txtEndDate

Me.RecordSource = "SELECT * FROM traffic where Date >= " & dteStart & "; "
End Sub
 
Try

Me.RecordSource = "SELECT * FROM traffic where Date Between #" & dteStart & "# AND #" & dteEnd & "#"

BTW, it is not wise to have a field named "date", as in some situations Access will confuse it with the Date() function.
 
I was close at one point but I had my # on the wrong side of the ". Not only does it work but I learned something
Thank you
Jim
 

Users who are viewing this thread

Back
Top Bottom