Results 1 to 3 of 3
  1. #1
    zivotopisac is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    2

    How to display data from a relation in a List Box?

    Hi, I wonder if anyone could help me with this.

    I made a database with 3 tables:
    "city"
    "company"
    "person"

    Each company has a director (I choose from a list that's bound to "person" by its ID field)

    Each person lives in a city (I choose from a list that's bound to "city" by its ID field)

    So:

    - a person's city is stored in "person" as the ID of "city", so I only have numbers (1, 2....)
    - there can be two persons in "person" with the same name (the only thing that differs them is the city they live in)

    The problem is:

    When I try to choose a director in "company" from a list, it shows me the name, surname and the ID of the city the person lives in, all from the table "person". The trouble is, since there can be two persons/directors with the same name, I really need to see their cities (the real city name, not just its ID). But I still want the city in "person" to be stored as ID of "city".

    I hope this makes sense, I would appreciate your advice very much. I attached my database so you can see what I'm writing about.



    practice.accdb

  2. #2
    helloworld's Avatar
    helloworld is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    10
    Let us say we had three tables:

    tblCompany
    CompanyCode - Primary Key
    CompanyName
    Director - Foreign Key (SSN)

    tblPersonnel
    SSN - Primary Key
    PersonName
    City - Foreign Key (CityID)

    tblCity
    CityID - Foreign Key
    CityName

    You would use the following SQL for your listbox:
    Code:
    SELECT tblPerson.SSN, tblPerson.PersonName, tblCity.CityName AS City
    FROM tblPerson INNER JOIN tblCity ON tblPerson.City=tblCity.CityID
    ORDER BY tblPerson.PersonName;

  3. #3
    zivotopisac is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    2
    Thank you so much!

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

Similar Threads

  1. Replies: 3
    Last Post: 02-12-2013, 11:26 AM
  2. Replies: 2
    Last Post: 04-05-2012, 08:39 PM
  3. Drop-Down list to display remaining text.
    By mnsemple83 in forum Forms
    Replies: 3
    Last Post: 07-18-2011, 10:29 AM
  4. Display list of people waiting
    By foxtet in forum Forms
    Replies: 1
    Last Post: 06-21-2011, 12:34 PM
  5. Combo Box List display HELP!
    By ehabo in forum Access
    Replies: 11
    Last Post: 01-04-2011, 12:55 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