Results 1 to 7 of 7
  1. #1
    CRobledo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    26

    main form and sub form with combo box filter

    I have a main form (Orchard input) with a table Sub form (orchard input form). What I would like to do is to have have a combo box in the main form that had certain criteria and based on what I select the sub form will filter to display any records that have that criteria in a specific field (UnboundOrchard) Ive tried a few things but I keep getting errors. Does anyone have any ideas on how to do this. I'm kinda new and running out of ideas.

    Here is the criteria. its located in a table called Orchard index in a field called OrchardName
    OrchardName
    3 Bucks (JD Orchards)
    Bandon Orchard
    Big Red Ranch
    Canyon
    G3 Orchards
    Graystone
    Hi-Point
    J&B
    Predator H&H
    Predator Ridge
    Quarry
    Red Bluff
    Roll 'Em


  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    ???? Can you try to describe this again? Forget the form and subform for the moment, just tell us in pain English or orchard talk,
    what exactly are you trying to do. Describe as you would to an 8 yr old.

  3. #3
    CRobledo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    26
    I would like for the combo box to be used to filter and show in the table only records for the values selected based on the unbound orchard field



    Click image for larger version. 

Name:	Capture.PNG 
Views:	26 
Size:	93.1 KB 
ID:	27711

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    ???I don't think we are communicating.
    Using Form and subform
    you would put a combo in the header of a form; rowsource of the combo is distinct Orchard (id or name..)
    Select an orchard in the combo,
    apply a filter to the recordsource of the subform,
    requery the subform and only records matching your criteria should be displayed

    Update: added subform to original post. It wasn't clear when re-reading my response..
    Last edited by orange; 03-03-2017 at 07:41 PM. Reason: clarify use of form and subform

  5. #5
    CRobledo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    26
    how do I apply a filter to the rowsource of the form?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    In your case, it seems to me since you have the names of the orchards, you would have a combo on the mainform whose
    rowsource was the names of the Orchards.

    The subform contains all data from your table you need including orchard name. That is it's recordsource is - Let's assume for this post it is - SELECT * from MyOrchardTable

    In the afterUpdate event of the combo (after you select the value you want) you would have code along my set up below.
    The sql for your subform record source will get modified based on the combo value selected on the mainform.


    This is from a sample I created for a different post which shows the general set up:

    Code:
    Private Sub txtFilter_AfterUpdate()
    '
    ' This sample contain information about Animals and where they were seen (Lat/Long) and when.
    ' The subform is linked to mainform on AnimalID
    ' In my sample I used a textbox as the filter to allow entry of any part or no keyword/string by using the like operator
    
    Dim sql As String
    
    'This  is the sql that serves as recordsource for my subform
    
     sql = "SELECT aname, [AnimalLocs].[SightingDate], [AnimalLocs].[GPSLong], " _
           & "[AnimalLocs].[GPSLat] " _
           & " FROM [AnimalLocs] Inner join Animal  " _
           & " ON [AnimalLocs].[AnimalId] = Animal.animalid " _
           & " Where aname like '*" & Me.txtFilter & "*' "
     
    ' these next two lines are the guts of the filter, and the syntax  says
    ' on me (mainform) using the AnimalLocsSubform control, which is a Form, set its recordsource =
    ' 1 - sets the subform recordsource  
           Me.AnimalLocsSubform.Form.RecordSource = sql
    
    ' 2 - tells Access to requery the subform
          
          Me.AnimalLocsSubform.Form.Requery
    
    End Sub
    To repeat:
    In your case, it seems to me since you have the names of the orchards, you would have a combo on the mainform whose
    rowsource is the unique names of the Orchards.
    eg: Select distinct OrchardName from myOrchardTable

    The subform contains all data from your table you need including orchard name. That is it's recordsource is - Let's assume for this post it is - SELECT * from MyOrchardTable

    So your
    Private Sub cboFilter_AfterUpdate()
    Dim sql As String
    sql = "SELECT * from MyOrchardTable " _
    & " where orchardname = '" & me.cboFilter &"' "

    and your 2 critical statements would be similar to mine, but using your subform control name
    and your name for the combo.

    There is a youtube video by Steve Bishop --he shows a keyword search with Form/subform and filter.
    He then requeries the sub form to use the textbox entry on the mainform as the new recordsource of the subform. You should watch this to get all the details.


    Good luck with your project.
    Attached Thumbnails Attached Thumbnails AnimalFormNoFilter.jpg   AnimalFormShowingAnimalsWithMinTheirName.jpg  
    Last edited by orange; 03-04-2017 at 07:17 AM.

  7. #7
    lacigol is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    14
    Quote Originally Posted by orange View Post
    Private Sub cboFilter_AfterUpdate()
    Dim sql As String
    sql = "SELECT * from MyOrchardTable " _
    & " where orchardname = '" & me.cboFilter &"' "
    Followed by:

    Me.[orchard input form].RecordSource = sql

    IMHO

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 05-10-2016, 06:07 PM
  2. Replies: 5
    Last Post: 08-26-2015, 12:09 PM
  3. Replies: 7
    Last Post: 07-01-2015, 10:29 AM
  4. Replies: 3
    Last Post: 06-02-2012, 07:39 PM
  5. LogIn Form to filter Main Form
    By ggs in forum Forms
    Replies: 5
    Last Post: 07-12-2011, 04:27 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