• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

filtering for date period

hey guys,

anything wrong with my this line of code?

Forms!frmMTKManager!subfrmServicingWorkHours.Filter = "[CalendarDate] >= #" & Format(Me.txtServicingWorkHoursStartDate, "m-d-yy") & "#"

gives me this error message 1
i want to filter the query from a certain date to a certain date = ) thanks guys!!
3 Solutions
To refer to a filter on a subform you use this syntax..


subformcontainercontrolname is the name of the subform control on the Main form that holds the subform.  It might have the same name as the subform it contains, but it could be different depending how it got there.  But in any case it is the name of that container control that is used.  The name of the subform is not relevant.
In addition to what Peter said, if your code is on the main form itself, you can refer to it using the Me keyword.
Me.subfrmServicingWorkHours.Form.Filter =

Ron G.
Jeffrey CoachmanMIS LiasonCommented:
Does this work?
Forms!mainFormName.subformcontainercontrolname.Form.Filter = "[CalendarDate] >=" & "#" & Me.txtServicingWorkHoursStartDate & "#"
...If txtServicingWorkHoursStartDate is a real date, then the format should not really matter.

Finally the format you are specifying is outdated ("m-d-yy")
1. This format will produce different length dates for single/double digit Months and dates:
...as opposed to a more standard format of "mm/dd/yyyy", which will produce:

2. That old format also does not clearly indicate what year you are specifying.
Is a year of 25, ...1925 or 2025?

developingprogrammerAuthor Commented:
hey peter, thanks!! it works like a charm! = )

ron, thanks, i knew we could use me to refer to the calling form but your bolding of the FORM word helped me spot the correct code i should use = )

thanks jeff! i always thought i had to put things in a certain format. now i know i don't need to so long as it's a real date. and yup i will bear in mind about the date format. thanks!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now