Results 1 to 8 of 8
  1. #1
    Maxjoo is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2024
    Location
    Carmel, Indiana, USA
    Posts
    18

    Question How to use a combo box in a form to show record(s) related to the chosen entry?


    Hello, every-1!!!!!!!...

    I have a form displaying data for buildings. I added a command button to display a second form showing record(s) related to the building on the first form. How can I use a combo box to choose the building I want, then, display the record(s) for that building?. I was trying to search other similar questions but(aab) "I've got lost in the jungle". I respectfully and humbly request a direct answer not reference(s) to another site. Thank You in advance!!!!!

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Set up a combobox with your building Primary key and Building name.

    In your command button put

    Code:
    DoCmd.OpenForm "Your form name",,,"BuildingID = " & me.YourComboBoxName
    the primary key is in the first column in the combo.
    you can add a test for the combo being not null also
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    See the DB I uploaded for another user as to one technique.
    https://www.accessforums.net/showthr...t=90129&page=2
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Maxjoo is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2024
    Location
    Carmel, Indiana, USA
    Posts
    18
    Hello moke123!!!!...

    I guess I am doing something wrong because I applied your solution, and it is not working. I have seen many similar codes and applied them with good results but this one is not working. Also, before opening this forum, I managed to get the combo box to display the list I want but(aab) when I click on any name nothing happens, it does not keep the focus...

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Here's 2 examples of what I think your trying to do.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    abuislam is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2024
    Posts
    4
    Quote Originally Posted by Maxjoo View Post
    Hello, every-1!!!!!!!...

    I have a form displaying data for buildings. I added a command button to display a second form showing record(s) related to the building on the first form. How can I use a combo box to choose the building I want, then, display the record(s) for that building?. I was trying to search other similar questions but(aab) "I've got lost in the jungle". I respectfully and humbly request a direct answer not reference(s) to another site. Thank You in advance!!!!!
    To display records related to a chosen building using a combo box, follow these steps:

    1. Add a Combo Box: Populate it with building IDs or names.
    2. Write a Query: Filter records based on the selected building ID.
    3. Use VBA: In the combo box's AfterUpdate event, set the filter for the second form.

    Example VBA code:
    vba

    Copy code


    Private Sub ComboBoxName_AfterUpdate()
    Me.SecondFormName.Form.Filter = "BuildingID = " & Me.ComboBoxName.Value
    Me.SecondFormName.Form.FilterOn = True
    End Sub


    Replace ComboBoxName and SecondFormName with your actual names.

  7. #7
    Maxjoo is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2024
    Location
    Carmel, Indiana, USA
    Posts
    18
    Thank You everyone who answered my post trying to help me out!!!! After many attempts, I could make the form to work the way I wanted. Thank You abuislam for your post/help!!!…

  8. #8
    Rickwave is offline Novice
    Windows 10 Access 2021
    Join Date
    Sep 2024
    Posts
    3
    To display related records based on a combo box selection, set the combo box to filter the form's data by linking the combo box's value to the form's record source through a query or macro. This will update the displayed records dynamically.

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

Similar Threads

  1. Show related record for current user
    By aquilina in forum Programming
    Replies: 20
    Last Post: 05-16-2014, 07:41 AM
  2. Replies: 7
    Last Post: 02-08-2014, 12:31 PM
  3. Replies: 7
    Last Post: 11-02-2012, 12:05 PM
  4. Show related data on a form
    By Accessgrasshopper in forum Forms
    Replies: 4
    Last Post: 03-17-2011, 07:53 PM
  5. Replies: 6
    Last Post: 07-19-2010, 10:57 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