Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2004, 03:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default Filter Subform B Based on Field in Subform A

I cannot get Access XP (2002) to recognize a subform's Filter property in this situation. Perhaps you can help me get the correct VBA.

Situation: Unbound Main form is open. It has two subforms, A and B. Both A and B are in datasheet view. Subforms A and B are based on two tables with one common field called lngFieldA.

What I want: When the cursor is placed inside txtFieldA in Subform A (i.e. txtFieldA has the focus), I want Subform's B filter to change. Right now, I have this in (Subform A) txtFieldA's On Got Focus event.

Me.Parent.Form.sfrSubformB.Form.Filter = "[lngFieldA] = " & Me.txtFieldA

That is, whatever value the cursor sits on in Subform A Field A, make SubformB's filter change so only Subform B Field A values are shown. However, I'm getting an error message saying that the filter property is not valid. Why not? I can do this:

MsgBox Me.Parent.Form.sfrSubformB.Form.Name, vbInformation, "Name"

and it will actually pop up a message box that says, "sfrSubformB". So if the .Name property works, why doesn't the .Filter property work? :(


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
 
Old June 16th, 2004, 11:55 PM
Authorized User
 
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this;
Me.Parent.Form.sfrSubformB.Form.Filter = "[lngFieldA] = " & Me.txtFieldA
Me.Parent.Form.sfrSubformB.Form.FilterOn = True

Just for the record, this syntax...
sfrSubformB.Form.Filter = "[lngFieldA] = " & Me.txtFieldA
sfrSubformB.Form.FilterOn = True
...should work.

& to show all records again, simply
sfrSubformB.Form.FilterOn = False

Hope this helps, good luck!


 
Old June 17th, 2004, 07:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Nope... none of that works. It's like just because I'm calling the .Filter property from Subform A and applying it to Subform B, it no longer exists in the library. The filter works great if I use it from the main form on a subform or from within the same subform, but if I use it from one subform to ANOTHER, it becomes invalid. :(

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old June 18th, 2004, 12:23 AM
Authorized User
 
Join Date: Oct 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry Greg, I took a bit for granted, at first.
This worked for me.
Forms!MainFormName![sfrSubformB].Form.Filter = "[lngFieldA] = " & Me.txtFieldA
Forms!MainFormName![sfrSubformB].Form.FilterOn = True

Hope this is the ticket!
Good Luck!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Subform Filter based on Multiselect Combo boxes natwong Access 2 November 16th, 2006 10:05 AM
Subform Filter using Multiple Combo boxes natwong BOOK: Expert One-on-One Access Application Development 0 November 13th, 2006 03:07 PM
Filter a subform based on value entered mackoy Access 1 August 25th, 2006 12:27 PM
subform based on a query Vince_421 Access VBA 2 May 10th, 2006 04:38 AM
Filter subform from main form DBoulos Access VBA 2 October 30th, 2003 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.