Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a Subform filter

Status
Not open for further replies.

CharlieT302

Instructor
Mar 17, 2005
406
US
Hi Folks,

I have a main form with two levels of subforms.
Main form
Subform1 (Begindate, Enddate) (Command Button)
Subform2 (Entrydate)

On Subform1, I have two unbound controls (Begindate, Enddate) used to store a filtering date. The EntryDate field on subform2 should show only those dates within the filtering range. The filter is triggered with a command button on subform1. I think I have a syntax error.

Current Filter:

stLinkCriteria = "Forms![frm Meal Orders]!frm_Meals_Schedule.Form!frm_Meals_Schedule_Mainsub.Form!Entry_date>=#" & Me!BeginDate & "# and forms![frm Meal Orders]!frm_Meals_Schedule.Form!frm_Meals_Schedule_Mainsub.Form!Entry_date<= #" & Me!EndDate & "#"

Forms![frm Meal Orders]!frm_Meals_Schedule.Form!frm_Meals_Schedule_Mainsub.Form.Filter = stLinkCriteria
Forms![frm Meal Orders]!frm_Meals_Schedule.Form!frm_Meals_Schedule_Mainsub.Form.FilterOn = True

Also, since this is code on subform1 referring to subform2, can this code be simplified?

 
Sounds like it would be much simpler to put the controls on subform 1 - (Begindate, Enddate) (Command Button) - on the main form. Then you'll only need one level of subform.

Max Hugen
Australia
 
Thanks Max,

Actually, I figured it out. The reason for the second subform was because the original subform had filter controls built into the header. When the screen was scrolled horizontally, the controls scrolled as well. The behavior was rather "clunky."

I had to modify the criteria:

stLinkCriteria = "[Entry_Date]>=#" & Me![BeginDate] & "# And [Entry_Date]<= #" & Me![EndDate] & "#"

This worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top