Selecting rows by date (1 Viewer)

Jim Stanicki

Registered User.
Local time
Today, 02:33
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
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:33
Joined
Aug 30, 2003
Messages
36,134
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.
 

Jim Stanicki

Registered User.
Local time
Today, 02:33
Joined
Aug 7, 2007
Messages
36
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

Top Bottom