Solved

Filter Subform using LIKE

Posted on 2013-12-26
7
1,060 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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 Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now