Results 1 to 6 of 6

How do I select the value of a combobox from a listbox selection?

  1. #1
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    50

    How do I select the value of a combobox from a listbox selection?

    This seems like something simple to Google, but I can't figure out how to ask the question so Google understands what I am looking for...

    On my form I have a combobox (cbxOffices) which is populated on form load. I also have a listbox (lbxAllotted) which is dynamically populated based on what the user selects from other controls on the form. What I want to happen is if the user double clicks lbxAllotted, it uses that value to select the corresponding item in cbxOffices.

    I had hoped cbxOffices=lbxAllotted would be the easy solution, but it's not.

    Thanks for the help!

    Scott

  2. #2
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,274
    I hate to say the blindingly obvious but why do you need a listbox and a combo box?
    Why not just use the listbox selection?
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment
    nil illegitimi carborundum est

  3. #3
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    50
    Quote Originally Posted by ridders52 View Post
    I hate to say the blindingly obvious but why do you need a listbox and a combo box?
    Why not just use the listbox selection?
    Lol, true enough. I may be making this more complicated than necessary!

    I'm also having a hell of a time writing the query for the listbox, so that makes having the combobox there easier.

    Maybe if I explain... I have a form where the user selects a course (eg, First Aid) from cbxCourses. Then they select a scheduled session from lbxSessions. lbxAllotment shows the number of seats allotted to each office and cbxOffices allows the user to also select an office. Right now, if the user selects an office from cbxOffices, it populates txtAllotment and the user can then change the number of seats.

    I'm trying to populate lbxAllotment with a list of all offices and their seat allotment. This query is putting my keyboard in a very dangerous situation right now!

    If I can get the listbox to properly show what I need it to show, then I can get rid of the combobox, making life easier!

  4. #4
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,274
    What situation is your keyboard in? Risk of fire? Danger of being hurled against the wall? Keys plucked out?

    Someone may contradict me, but I believe a listbox can do everything that a combo can do plus you have the option of multi-select
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment
    nil illegitimi carborundum est

  5. #5
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    50
    Mostly being smashed into little pieces!

    Thanks for your help today on the query, but this issue still stands as I can't properly populate the listbox with the info I need.

    So, is there a way to use the value of the listbox to pick the corresponding item in a combobox?

    Thanks,

    Scott

  6. #6
    ridders52's Avatar
    ridders52 is offline Voodoo Is Practised
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    2,274
    Firstly I'll repeat my earlier comment - this is an unnecessarily complicated method of working.
    The correct approach is still to fix your query ... the one from the other thread

    However doing this is extremely easy.

    The listbox must be simple select as combos can only have one value
    Both combo & listbox need to be bound to the same field - normally the primary key field which should be hidden in both controls
    Add code to the after update event of the listbox:

    Code:
    Private Sub ListboxName_AfterUpdate()    
    Me.ComboName = Me.ListBoxName
    End Sub
    That's it!
    See attached for a very simple example
    Attached Files Attached Files
    Last edited by ridders52; 06-15-2018 at 03:44 AM.
    Colin (Mendip Data Systems), Website, email
    If this has helped, please click the star button and leave a comment
    nil illegitimi carborundum est

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

Similar Threads

  1. Replies: 7
    Last Post: 04-28-2017, 11:52 AM
  2. Replies: 3
    Last Post: 01-20-2017, 01:25 PM
  3. Replies: 2
    Last Post: 01-20-2017, 09:26 AM
  4. Combobox selection populates Listbox
    By Thompyt in forum Programming
    Replies: 9
    Last Post: 09-24-2015, 12:55 PM
  5. Replies: 1
    Last Post: 09-10-2012, 10:21 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
  •  
Tech Forums: Microsoft Office Forums