Results 1 to 5 of 5
  1. #1
    pooldead is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    26

    Combo Box Query Problem

    I am working on a form in my DB that will pull user information based on a user ID. Everything is working, except that I cannot get my combo boxes to populate unless the associated list box item is selected. Let me explain further.



    I am currently running this code to pull the user's location information from the table:

    Me.lbox_LocOut.RowSource = "SELECT tbl_Users.Location " & _
    "FROM tbl_Users " & _
    "WHERE ((tbl_Users.[Primary_User_ID])='" & Me.txt_SearchUser & "');"

    That works fine. I am running a similar piece of code in a combo box to pull a list of applications to select from that is based on what location is selected. This code is set to run as lbox_LocOut_AfterUpdate().

    Me.cbox_AppOut.RowSource = "SELECT tbl_Applications.Application_Name " & _
    "FROM tbl_Applications " & _
    "WHERE ((tbl_Applications.[Location_Name])='" & Me.lbox_LocOut & "');"

    This code does work, but only if I click into the "lbox_LocOut" field once the information has loaded. I would like to have the combo box update automatically without having to click into the listbox.

  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,726

  3. #3
    pooldead is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    26
    Thanks orange. I'm going through that information now. I did have a thought, but I'm not sure how to make the syntax work. Within the line of code for my combo box: "WHERE ((tbl_Applications.[Location_Name])='" & Me.lbox_LocOut & "');" would it be possible to change the me.lbox_locout to be a specific field from a different table.

    So for example, if I changed it to something like
    "WHERE ((tbl_Applications.[Location_Name])= tbl_users.location);", effectively ignoring the field in my form and going straight to the table source to find the information for the criteria.

  4. #4
    pooldead is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    26
    Marking this as solved. For the sake of anyone that may come across this in the future, I wanted to note what I did to make this work:

    For other functions in my form to work correctly, I had to change many of my list boxes to text boxes and write a small bit of code to output the same information into the text box. After that, I just updated my WHERE statements to match the location_name to the new text box.

    Code:

    Text Box populate:
    Me.txt_LocOut = DLookup("Location", "tbl_Users", "tbl_Users.[Primary_User_ID] = '" & Me.txt_SearchUser & "'")

    Combo Box Update:
    Me.cbox_AppOut.RowSource = "SELECT tbl_Applications.Application_Name " & _ "FROM tbl_Applications " & _
    "WHERE ((tbl_Applications.[Location_Name])='" & Me.txt_LocOut & "');"

    This has the added benefit of allowing me to manually change the data in the txt_LocOut box and automatically updating my combo boxes after tabbing out of the txt field.

  5. #5
    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,726

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

Similar Threads

  1. combo box problem
    By Johnny Chow in forum Access
    Replies: 4
    Last Post: 12-24-2018, 09:31 PM
  2. Replies: 5
    Last Post: 12-04-2017, 03:06 PM
  3. Replies: 15
    Last Post: 07-20-2013, 12:42 PM
  4. Combo box problem
    By CARL_ARNAIZ in forum Access
    Replies: 1
    Last Post: 05-10-2011, 08:54 AM
  5. Problem with combo box
    By osimini in forum Forms
    Replies: 5
    Last Post: 05-25-2009, 03:08 PM

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