Acess VBA Combo box

Posted on 2011-05-02
Last Modified: 2012-05-11
Following is the scenario I am dealing with...

I have the combo box with two columns

Name  Age
David 29
David 32
Peter 24
Peter 25
Peter 26
Peter 29
Maria 22
Maria 29

I selected Peter 26, and after selecting when I go back to drop down combo, it is always on Peter 24, how do I code it to have it keep the selection ie Peter 26

Question by:hitsdoshi1
    LVL 119

    Accepted Solution

    use the Age column as the bound column or reverse the field in the rowsource of the combo box.

    the duplicates names is the one causing the selected item in the combo to revert to the first of the duplicate names.
    LVL 12

    Assisted Solution

    How do you populate your Combox?
    Is it an Unbound textbox, with as source your values?
    Or is it bound to a Field from a Table/Query?

    If its bound then it will always goes to the value stored in the table.

    LVL 44

    Assisted Solution

    If you are using a combo box in which you are trying to assess two fields, you must make the query of the combo box a concatenation of the two fields - SELECT fName & " " & Age From People;

    You can only  'Bound' to one field - but

    in fact there are two.
    LVL 10

    Expert Comment

    I'd suggest adding an ID field so each row is unique and then bind your combo box to that ID field.  It is quite possible to have two Davids who are the same age.  So using either the name or NameAge as your key is not at all reliable.
    LVL 9

    Author Closing Comment

    Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now