Solved

Filter Subform using LIKE

Posted on 2013-12-26
7
1,167 Views
Last Modified: 2013-12-31
Hello Experts.

Is it possible to filter a subform using a LIKE statement that refereneces a text box on the form?  If yes, could you help with my code?

Thank you.

Me.subForm.Form.Filter = "Like '*' & Me.subForm.Form![txtbox] & '*' "
Me.subForm.Form.FilterOn = True
0
Comment
Question by:dhemple
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 500 total points
ID: 39740341
You need to specify a field name and correct the quotes:


Me.subForm.Form.Filter = "[TheFieldIWantToFilter] Like '*" & Me.subForm.Form.[txtbox] & "*' "

Open in new window

0
 

Author Comment

by:dhemple
ID: 39740361
Thank you for your response.

I made the changes to my orginal code as you have exampled.  I'm getting a Run-time error '2465': Microstoft Access can't find the field '|1' referred to in your expression.

Any idea why this is occuring?

Orginal Code:
Me.[frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData_SubFrm].Form.Filter = "[IPD_New_BrandName] Like '*" & Me.[frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData_SubFrm].Form.[txtSearchBrand] & "*' "
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39740378
Try this variation:

With Me.[frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData_SubFrm].Form
           .Filter = "[IPD_New_BrandName] Like '*" &  .txtSearchBrand & "*'"
           .FilterOn = True
End with

Open in new window


And post back with any errors.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 61

Expert Comment

by:mbizup
ID: 39740380
As an aside, your naming conventions *might* be problematic.  Best practice is to avoid spaces and special characters in your variable and object names.
0
 

Accepted Solution

by:
dhemple earned 0 total points
ID: 39740424
The code you provided gave me the same error.


I found a solution..  for whatever reason the code did not like the use of "Me."  I had to use the actual Main Form name to get it to work.

Working code:
Forms![frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData]![frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData_SubFrm].Form.Filter = "[IPD_New_BrandName] Like '*" & Forms![frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData]![frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData_SubFrm].Form.[txtSearchBrand] & "*' "
Forms![frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData]![frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData_SubFrm].Form.FilterOn = True

Summary of working Code:
Forms![MainForm]![SubForm].Form.Filter = "[Field To Filter On] Like '*" & Forms![MainForm]![SubForm].Form.[txtbox] & "*' "

Forms![MainForm]![SubForm].Form.FilterOn = True
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39740468
"Me"  means the 'current form'.

If the code was located somewhere on frm_PremierProdLaunchPlanW/OMatchingtbl_IPD_NewData, then 'Me' would work.

If it was located elsewhere, such as a function in a public module, then the full form reference, as in your posted solution, is required.
0
 

Author Closing Comment

by:dhemple
ID: 39747879
Thanks for your help.  Your code helped me in solving the issue.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access lists formating 8 49
Access Form - Button Format Issue 13 46
Excel graph in access report 1 32
Access 2010 Changing String to Date with Leading Zero 11 31
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question