Solved

Filter Subform using LIKE

Posted on 2013-12-26
7
1,087 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

948 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

20 Experts available now in Live!

Get 1:1 Help Now