Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218

    Trouble filtering combobox


    I'm trying to filter one combobox based on the values of another combo box.

    I have a buildings table and a rooms table. There are many rooms in one building and a room can have the same name but be in a completely different building, and thus, be a completely different room. I have a subform which allows me to select a building name. But when I try to select a room, it shows duplicate values as well as rooms which do not belong to that building.

    I've tried the method of creating two combo boxes and adding the building ID to the room combo box and then specifying the building combobox. It doesn't work, it asked me to enter parameter value for [forms]![frmBuildings]![BuildingName]. If I hit cancel and try to select a building, there is nothing in the rooms combobox. I've tried this using unbound combo boxes and it worked just fine. But I need them to be bound to a ID, so that won't work.

    I've tried doing this using VBA, but I couldn't get the code right. Your help is appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,746
    Cascading combo videos 1 and 2

    Use Google and research MSAccess cascading comboboxes
    Good luck.

  3. #3
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    I've watched both videos. As well as every video I could find on youtube in regards to cascading comboboxes.

    I cannot get it to look into my combo box for a value as it should. It always asks me to enter parameter value. I've tried changing the combobox name, nothing is working.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    We need to review the setup. You can either list the relevant combobox properties and their settings or provide db - follow instructions at bottom of my post.
    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.

  5. #5
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    Quote Originally Posted by June7 View Post
    We need to review the setup. You can either list the relevant combobox properties and their settings or provide db - follow instructions at bottom of my post.
    I won't be able to upload the db until I get to work tomorrow morning.

    I think I figured out why its not working though. These cascading comboboxes are in a subform which is attached to my mainform. According to this, http://www.pcreview.co.uk/threads/su...query.3225031/, I can't refer to the subform, I have to refer to the control containing the subform.

    Their example is this: [Forms]![myParentForm]![NameOfControlThatContainsTheSubform]![cboRoute]

    To be honest I have no idea what the control that contains the subform is called. I do know my parent form is frmMainCustomers so I tried [forms]![frmMainCustomers]! which access 2010 automatically gives me all the options for frmMainCustomers but none seems to get me to my combo box.

  6. #6
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    I figured it out!

    It is important to select the actual name of the subform which is linked to the mainform. I had forgotten, when I created my subform the name I wanted was already taken so I renamed it to "POC." Even after I renamed the subform to frmBuildings, my main form still saw it as POC.

    So for anyone else having this issue, if the combo box is inside of a subform which is linked to a main form, you need the parent form first, then the subform, then the combo box name.

    In my case, [Forms]![frmMainCustomers]![POC]![BuildingName]

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Actually, if both comboboxes are on the same form, even a subform, the second combobox RowSource can be simply like:

    SELECT ID, LastName FROM Customers WHERE BuildingID = [combobox1name];
    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.

  8. #8
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    Interesting. I could've swore I tried just [Building Name] as the criteria in design view of the query and it didn't work. Will try that again tomorrow and see what I get.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    That is an SQL statement in RowSource, not a query object.
    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.

  10. #10
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    If I go to row source and click on the three dots it opens up a query design page. And i can go to sql view if i want to. Isn't that the same thing?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Yes, can do that or simply type out the SQL statement directly in the RowSource.
    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.

  12. #12
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    BuildingsSwitches3.zipI'm having problems with my combobox. I thought it was working but after further testing, I found that if I open up frmMainCustomer and select a building name under the subform, I can then select a room name. I only see the rooms which are in that building and everything works great. However, if I go down a line and select a second building (as each customer can own more than one building/room, after I then select a room for that second building, the room for my first building disappears. it does not allow me to store multiple values. What am I doing wrong?

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Unfortunately, dependent combobox with lookup alias doesn't work nicely in continuous or datasheet view form. Because once the combobox RowSource is filtered, the alias values for other records are not available for display. This is a known condition discussed in many threads and dealing with it is not simple.

    An alternative is to not use lookup alias. Since your building name values are so small (just numbers up to 4 digits) could just save the BuildingName value instead of BuildingID. Then the BuildingID field becomes unnecessary.
    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
    ittechguy is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    218
    Interesting. Well most buildings are numbers with up to 4 digits but a couple are words up to 10 letters. I had thought about having my buildings table have only one field, make it text and set it to indexed, no duplicates.

    Afaik, I need the building ID because I can't just select a building name, I need the ID.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    No, this can be designed to eliminate the BuildingID. It's just an autonumber field to generate a unique record identifier. Your BuildingName values are unique so the table actually has two unique identifiers. The autonumber is really not needed in this case and eliminating would simplify the situation. If the building name values were long like: 'Alaska Native Science and Engineering Program' then might want to use the autonumber ID. But memory is cheap these days and saving long text identifiers not such a big deal and if your db is not terribly large, indexing on text fields probably not an issue. Another reason to save the ID is to keep the db size down because repeatedly saving long text values can use up Access 2GB limit. But again, if the db remains small, not an issue.

    Also, the RoomID in Rooms is not needed if you want save both building and room identifier into the record.

    Just have to decide what works best for you. As I said, dealing with lookup alias in dependent combobox on continuous or datasheet form will not be simple.
    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.

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

Similar Threads

  1. Trouble with filtering underlying form
    By Mubashir sabir in forum Forms
    Replies: 2
    Last Post: 07-14-2015, 03:54 AM
  2. Subform combobox filtering
    By warren0127 in forum Forms
    Replies: 14
    Last Post: 05-27-2015, 11:23 AM
  3. Replies: 1
    Last Post: 05-24-2014, 09:08 AM
  4. Filtering out data for combobox
    By wlanssens in forum Access
    Replies: 4
    Last Post: 01-02-2014, 05:00 PM
  5. Combobox Filtering in Form
    By dgwynn in forum Forms
    Replies: 6
    Last Post: 09-27-2012, 08:15 PM

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