Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 16th, 2004, 03:51 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Reply With Quote
  #2 (permalink)  
Old June 16th, 2004, 11:55 PM
Authorized User
 
Join Date: Oct 2003
Location: Toronto, Ontario, Canada.
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!


Reply With Quote
  #3 (permalink)  
Old June 17th, 2004, 07:28 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Reply With Quote
  #4 (permalink)  
Old June 18th, 2004, 12:23 AM
Authorized User
 
Join Date: Oct 2003
Location: Toronto, Ontario, Canada.
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!


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.