Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 28th, 2009, 12:26 AM
WarriorMCB WarriorMCB is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2007
Posts: 69 WarriorMCB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 9 m 43 sec
Reputation Power: 3
Filter Multi SubForms from the mainform filter

Hi DBer's

Here's one for the books! How u set a combo (unbound) box to pull up names from records that when the selection is chosen the subforms filter the said choice.

The subforms are link master & child SchedID.

Thanks
MCB

Reply With Quote
  #2  
Old September 28th, 2009, 11:56 AM
Kafrin Kafrin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: Dorset, UK
Posts: 10 Kafrin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 55 sec
Reputation Power: 0
One way is to set the Filter and FilterOn properties of the subforms.

In the AfterUpdate of the combo you'll need code like:

Me!SubformControlName.Form.Filter = "SubformFieldName = " & Me!ComboBoxName
Me!SubformControlName.Form.FilterOn = True

Don't forget that if the field you're filtering isn't numeric you will need to adapt the filter string:
For text: SubformFieldName = '" & Me!ComboBoxName & "'"
For dates: SubformFieldName = #" & Format(Me!ComboBoxName,"m/d/yy") & "#"

Reply With Quote
  #3  
Old September 28th, 2009, 09:00 PM
WarriorMCB WarriorMCB is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2007
Posts: 69 WarriorMCB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 9 m 43 sec
Reputation Power: 3
Thanks, with a little tweaking it worked!

Now that I have this code right

Me.GMon8a.Form.Filter = "Technician = '" & Me.Combo569 & "'"
Me.GMon8a.Form.FilterOn = True

If say I need to add a second field name to the filter, how would it added?

Last edited by WarriorMCB : September 29th, 2009 at 12:21 AM.

Reply With Quote
  #4  
Old September 30th, 2009, 06:33 AM
Kafrin Kafrin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Location: Dorset, UK
Posts: 10 Kafrin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 55 sec
Reputation Power: 0
You can just concatenate, eg:

Code:
With Me.GMon8a.Form

.Filter = .Filter & "And SecondField = '" & SecondCombo & "'"
.FilterOn = True

End With

Be aware that this will cause you problems if there's not already something in the filter.


If you have a number of filtering combo boxes I suggest a slightly more robust method that also makes it easier to empty out the filter. In the main form module, add a sub like:

Code:
Private Sub FilterSubform()
With Me.GMon8a.Form
    .Filter = ""
    .FilterOn = False
    
    If Not IsNull(Me.Combo569) Then .Filter = "Technician = '" & Me.Combo569 & "'"
    
    If Not IsNull(Me.SecondCombo) Then
        If .Filter <> "" Then .Filter = .Filter & " And "
        .Filter = .Filter & "SecondField = '" & SecondCombo & "'"
    End If

    If Not IsNull(Me.ThirdCombo) Then
        If .Filter <> "" Then .Filter = .Filter & " And "
        .Filter = .Filter & "ThirdField = '" & ThirdCombo & "'"
    End If
    
    If .Filter <> "" Then .FilterOn = True
End With
End Sub


Keep adding to this sub for each combo. Then you need AfterUpdate code for every sub:
Code:
Private Sub Combo569_AfterUpdate()
    FilterSubform
End Sub

Repeat for each combo in the FilterSubform sub.
This method also works for text boxes used for filtering. There is a character limit for filter strings. I can't remember for definite but I think it's 256 characters. You're unlikely to hit the limit using this method.

Note that the FilterSubform sub is Private; this means that other subs in the smae module can use it, but subs in other modules cannot see it at all.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Filter Multi SubForms from the mainform filter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek