Apply filter to subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I got a form (not bound) which has a datasheet subform.
I want to make a button on the form to filter out the subform values.
I thought this should be a correct reference, but it doesnt work:

DoCmd.ApplyFilter "", "Me!ListSub1.English Like (""*""+[Find an English
Word]+""*"")"

It gives a message that "The action or method is invalid because the form or
report isn't bound to a table or query"

Help please! I am desperate....
Thank you.
Lana
 
Lana said:
Hi all,
I got a form (not bound) which has a datasheet subform.
I want to make a button on the form to filter out the subform values.
I thought this should be a correct reference, but it doesnt work:

DoCmd.ApplyFilter "", "Me!ListSub1.English Like (""*""+[Find an English
Word]+""*"")"

It gives a message that "The action or method is invalid because the form or
report isn't bound to a table or query"


That problem is because the DoCmd actions can't tell whether
you want to operate on the main form or a subform. Since
you main form is unbound, I think you can get away with
using the Filter property.

Also you must filter a **field** in the subform's record
source table/query, not a control on the form:

Dim strWord As String
strWord = InputBox("Find an English Word")
With Me.ListSub1.Form
.Filter = "English Like ""*" & strWord & "*"" "
,FilterOn = True
End With

You can avoid the popup prompt for a word, by adding a text
box to your main form's header section and using that in the
filter:

With Me.ListSub1.Form
.Filter = "English Like ""*" & Me.textboxname & "*"" "
,FilterOn = True
End With
 
Back
Top