Results 1 to 3 of 3
  1. #1
    poppet is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2014
    Posts
    18

    Filtering using multiple fields

    Hi,


    How does one filter using multiple fields on a form?

    If I have a pet database that has the following fields

    petid
    type
    name

    On a form I wish to select a pet type from a drop down box that shows a list of unique types of pets in the database (cat, dog, elephant).
    If I select cat then in the next field I would like to select the cat's name from a drop down.
    Then I would like to save the pet id for this selected pet in petid.

    I guess it is a combination of combo box and save value for later use and then perform an updated query?
    If it is this can you describe how you perform this updated query please?
    Regards,
    David.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    In the type combo AFTERUPDATE event
    change the query to the Name combo box.
    1 query is all the names, 1 query is filtered by the box: (select names from table where [type] = forms!frmMyForm!cboType)

    Code:
    sub cboType_Afterupdate()
       if isNull(cboType) then
             cboName.rowsource = "qsAllAnimals"
       else
             cboName.rowsource = "qs1Animal"
       end if
    end sub

  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
    53,632
    Is this form bound to table?

    Could make the names combobox RowSource like:

    SELECT ID, names FROM Pets WHERE type = [cboType];

    Then in cboNames GotFocus event:

    Me.cboNames.Requery

    Bind cboNames to the ID field.

    Also might want code in cboType AfterUpdate event that sets cboNames to null

    Me.cboNames = Null
    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.

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

Similar Threads

  1. Filtering and Display of Multiple Date Fields
    By stevekroll in forum Queries
    Replies: 3
    Last Post: 03-17-2014, 07:59 PM
  2. Filtering by multiple fields
    By rhubarb in forum Queries
    Replies: 1
    Last Post: 12-05-2013, 04:34 PM
  3. Replies: 5
    Last Post: 08-07-2012, 10:12 PM
  4. Replies: 2
    Last Post: 02-20-2012, 08:32 AM
  5. Replies: 1
    Last Post: 08-09-2011, 11:13 AM

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