Me.filter between 2 dates



If IsNull(Me.BeginDate) Or IsNull(Me.EndDate) Then
Me.FilterOn = False
Me.Filter = "[SoldDate] = #" & (Between [BeginDate] and
Me.FilterOn = True
End If

I'm not sure what code I need to get this to work but I have to
unbound text boxes that are called BegineDate and EndDate. I have a
command button that needs to filter the form when I click it.

Me.Filter = "[SoldDate] = #" & (Between [BeginDate] and [EndDate]) is
not correct and I know this but it's the best example I can give
because I'm not sure how the colde should look. The SoldDate is what
is filtering the form and it needs to show any orders that were
between BeginDate and EndDate.



I found out the code that works:

Me.Filter = "[SoldDate] Between " & CLng(Me.BeginDate) & " And
" & CLng(Me.EndDate)

Paul Shapiro

Your original expression:
Me.Filter = "[SoldDate] = #" & (Between [BeginDate] and [EndDate])
could be corrected to:
Me.Filter = "[SoldDate] Between [BeginDate] and [EndDate]"
assuming that all 3 of those fields are datetime data types. The # character
delimits literal dates:
Me.Filter = "[SoldDate] Between #1/1/2009# and #1/31/2009#)

When you use the CLng, you are removing the time portion of the data, so
3/17/2009 11:40pm becomes 3/17/2009 12am. By adding it as a string, you're
including the literal integer that represents the day for your Begin and End
dates. If you don't need that truncation, the first line I showed above
would be cleaner.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question