Link to home
Start Free TrialLog in
Avatar of Paul McCabe
Paul McCabe

asked on

Filtering a Continuous Form by Date Ranges in VBA

I am an MS Access beginner using version 2013. A button opens a continuous form that I would like to filter for records in the range of ten days before the current date and 30 days after the current date (i.e. a 40-day period). I have tried various pieces of code for the button's on-click event, including the following, but just cannot get it to work.

DoCmd.OpenForm " Form_Projects", , , "Date= Between Date()-10 And Date()+30"

The expression Between Date()-10 And Date()+30 works fine in queries, but not in VBA, as I keep getting an error message telling me the code structure is wrong. Could anyone help point me in the direction of the correct VBA expression that should be used ?
SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or possibly

DoCmd.OpenForm " Form_Projects", , , "[Date] >= "#" & Date()-10 & "#" And [Date] <= "#" & Date()+30 &"#""
Avatar of Paul McCabe
Paul McCabe

ASKER

Roy's first solution and Dale's suggested solution worked fine. Dale, your points are well made. Thank you both !
glad to help.