Filter subform based on text box value

Hi,

I'm trying to pass a value from a text box on a form to a subform on the same form in order to filter the subform.

Private Sub CmdSearchProperties_Click()

Me.[CAG_subform].Form.Filter = "[cagPostCode] = " & Me.txtPostcode.Value
Me.[CAG_subform].Form.FilterOn = True
Me.[CAG_subform].Form.Requery
End Sub

Open in new window


The code 'seems' ok to me but every time i press the SearchProperties button i get an error:

'Microsoft Office Access can't find the field 'pipe' referred to in your expression.'

Any ideas? presuming i've just got syntax wrong?

I've also read that filtering is a bad idea, if so, what other methods can i do to pass the text box value to the datasheet so that only records that match the textbox value appear?

Best regards

Brendan
eyeisystemsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
maybe the field [cagPostCode]  is TEXT
try

Me.[CAG_subform].Form.Filter = "[cagPostCode] = '" & Me.txtPostcode.Value & "'"
eyeisystemsAuthor Commented:
Yeah the [cagPostCode] field is TEXT but still same error unfortnately. :(
Dale FyeOwner, Developing Solutions LLCCommented:
First, you can do away with line #5 above, you do not need to requery the form after setting the filter and turning the filter on.

Next, I would attempt to open the subform in stand-alone mode and see if you get that message doing that.  If so, you probably have a reference in the OrderBy or Filter property of the subform itself.  You might also be referring to a field in the underlying query which does not exist.
Rey Obrero (Capricorn1)Commented:
open the main form in design view

see the name of the SUBFORM CONTROL NAME and use that name instead of [CAG_subform]


Me.[nameOFsubformControl].Form.Filter = "[cagPostCode] = '" & Me.txtPostcode.Value & "'"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eyeisystemsAuthor Commented:
Bingo Rey!

Sub form control was named 'Property Address Search' and that solved the problem!

Many thanks

Brendan
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.