Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22

    Question Filtering form data based on selection from Combo box

    Hi all,

    Sorry if this is Access 101 stuff but I am an access amateur and trying to create a DB for use in our office as a once off.

    I have a main Clients with a subform of ClientReturns (Tax). Each client is assigned one client partner in the company of which there are 6. Joe Bloggs is one of these managers and I want him to be able to filter the form so he only sees his clients. These client partners are stored in their own little table.

    So I have been reading how to accomplish this but cannot get it to work.I have a query called qrySelectCROPartner and on the form I have the combo box on the form setup to get its values from the partner table mentioned above. The criteria in the query then points to the combo box on the form like so: [forms]![frmCROReturns]![Combo16]

    Full query being: SELECT Clients.ClientID, Clients.ClientName, Clients.PartnerFROM Clients
    WHERE (((Clients.Partner)=[forms]![frmCROReturns]![ComboPartner]));

    Doesn't work when I run the form anyway, changing the partner select in the combo box achieves nothing.



    Your direction is much appreciated!
    Thanks

  2. #2
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    You have to requery your subform on the combo box update event.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    In VBA, like:

    Sub comboboxname_AfterUpdate()
    Me.Requery
    End Sub

    However, the Requery syntax depends on where the combobox is in relation to the parameterized query. Are they both part of the subform? If yes, then use what I show.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22
    Tried that still no joy. The combo box isn't part of the subform, its on the main form.

    The main form,should it be based on the client table or the qry selecting from it?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    The query must be used as the main form RecordSource.

    Also, is Partner a number field for a partner unique ID? Is the combobox bound to column Partner value?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22
    Ok, figured as much re the query.

    Partner is text, a single field table with the partner as the PK. So JBloggs/ESmith/etc

    Combo box is bound to the Partner value yes. Screenshot attached if that helps?Click image for larger version. 

Name:	partner.jpg 
Views:	24 
Size:	129.3 KB 
ID:	15294

  7. #7
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    June7 was close. I don't think he realized your query was on a subform.

    In your main form, behind the ComboBox update event use this..
    Code:
    Private Sub Combo16_AfterUpdate()
         Me.SubformName.Requery
    End Sub

  8. #8
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22
    Should the query select the partner from the clients table or from the partners table?

    Theres a one-to-many relationship between partners and clients.

  9. #9
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22
    Also in case its important, the partners field in the clients tale is a lookup field based on the partners single text field table

  10. #10
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Quote Originally Posted by barryg80 View Post
    Should the query select the partner from the clients table or from the partners table?

    Theres a one-to-many relationship between partners and clients.
    It really wouldn't matter since presumably the Client.Partner field is the foreign key of your partners table... but here you aren't even doing a join between the two tables anyway. Filtering your clients table should be fine.

  11. #11
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22
    Quote Originally Posted by Xipooo View Post
    It really wouldn't matter since presumably the Client.Partner field is the foreign key of your partners table... but here you aren't even doing a join between the two tables anyway. Filtering your clients table should be fine.
    Thanks, relationship is this..Click image for larger version. 

Name:	tables.jpg 
Views:	21 
Size:	16.5 KB 
ID:	15295

  12. #12
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    The relationship isn't used in your query that populates the subform though.

    If I understand correctly this is the query which is the source for your subquery right?
    Code:
    SELECT Clients.ClientID, Clients.ClientName, Clients.PartnerFROM Clients
    WHERE (((Clients.Partner)=[forms]![frmCROReturns]![ComboPartner]));
    


    Since there is no join statement and you aren't bringing in the Partners table in your FROM, the relationship is irrelevant to the query.


  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,945
    Filter the main form to the Client Partner and the linked subform should show only those clients that are associated with the Partner.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Quote Originally Posted by June7 View Post
    Filter the main form to the Client Partner and the linked subform should show only those clients that are associated with the Partner.
    You know, you just made me realize he's probably using a Master/Child filter, not a query to do the filtering for him. My bad.

  15. #15
    barryg80 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    22
    Maybe I am totally astray here folks. I have the combo on the main form along with clinetid and name. I filter by partner and it shows only clients of that partner on the main form. As in you can navigate from one to the next. In the subform it shows tax details of the selected client..

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 02-07-2013, 09:01 PM
  2. Replies: 1
    Last Post: 10-30-2012, 10:29 AM
  3. Replies: 1
    Last Post: 10-25-2012, 12:58 PM
  4. Replies: 5
    Last Post: 03-12-2012, 02:58 AM
  5. Replies: 1
    Last Post: 02-25-2011, 10:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums