Filter by Selection Button Doesn't Work

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have this code on a command button on the main form "DaysTerm"
The field "StartDay" is a combobox, column1 is ID, column2 is Day on the
SubForm..."DaysTermSub".
When I try to run it I get a message "Does not apply to Object"
I really want it to be like the Query by Selection where yo click on the
field and you can Filter things like that. But if I get it to work on
this one field I'll be happy!
Thanks
DS


Forms!DaysTerm.DaysTermSub.Form!Filter = "StartDay = " &
Forms!DaysTerm.DaysTermSub.Form!StartDay
Forms!DaysTerm.DaysTermSub.Form!FilterOn = True
 
Hi DS

Filter and FilterOn are *properties* of a form, so you should use a dot
reference, not a "!". (The "!" refers to a member of an objects default
collection, and in the case of a form, this is the Controls collection.)

Also, as your command button is on Forms!DaysTerm, you can substitute "Me".

Finally, a With statement will simplify your code somewhat.

So, try this:
With Me!DaysTermSub.Form
.Filter = "StartDay = " & !StartDay
.FilterOn = True
End With

This will work only if StartDay is numeric. If it's a date/time field, then
you will need to format the date correctly and enclose it in "#" signs:

.Filter = "StartDay = " & Format( !StartDay, "\#mm/dd/yyyy\#" )
 
Back
Top