Solved

In MS Access, how can I change a key # to the name?

Posted on 2014-11-26
9
111 Views
Last Modified: 2014-11-26
Hello,

This question is probably really simple for someone who uses Access regularly, however, my experience level is pretty basic.  

I have created a query to pull all of our salespeople's production for a period of time.  The table I'm referencing contains:
- Key #
- Sales people's "Name" (as well as supervisor names)
- Supervisor key #

My question is:  In the query, how can I get the Supervisor's name to show rather than their key #?

For example:
Key   Name    Super #
1  Tom Jones  4
2  E Kline          4
3  J Doe             4
4  S Meyer       7

The query now would pull:   Tom Jones, 4, rather than Tom Jones, S Meyer.

Thank you,

Pat
0
Comment
Question by:FFNStaff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 36

Expert Comment

by:PatHartman
ID: 40467080
You need to join the table to itself.  This is known as a self-referencing relationship since a foreign key in the table refers to the table's own primary key.

Select tblPersons.*, tblPersons_1.LastName As SupervisorLastName, tblPersons_1.FirstName As SupervisorFirstName
From tblPersons Left Join tblPersons as tblPersons_1 On tblPersons.SupervisorID = tblPersons_1.PersonID;
0
 

Author Comment

by:FFNStaff
ID: 40467217
Pat, thanks for responding.

I don't understand what you telling me to do.  Am I doing this is the query grid under Field or Table?  Am I building this?

If it would help, I'm using the table with the salespeople's information, which is named Salespeople.
The columns are named:
S_ID,
S_LNAME,
S_SUPERVISOR_A_ID
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40467317
The table I'm referencing contains:
 - Key #
 - Sales people's "Name" (as well as supervisor names)
 - Supervisor key #


Now, you want the supervisor's name.  It isn't in this table, right?
So in the query designer, you need to add the table containing the names.
You then need at create a join by dragging the supervisor's key # in the table you originally referenced to the table you just added (Access may have been smart enough to create this auto-magically if both keys were named the same, conversely Access may have created an unwanted join if the key name in the added table matched a name in the originally referenced table that we presently do NOT want to join on)
Then add the supervisors name field from the newly added table to the grid.

Example attached
sales.mdb
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 40467365
you have to join with the supervisors table with the key supervisor_a_id
0
 

Author Comment

by:FFNStaff
ID: 40467408
The supervisors are in the same table as the salespeople.
0
 

Author Comment

by:FFNStaff
ID: 40467417
the Supervisors are treated as salespeople in the same tables.  They are not necessarily identified as supervisors.  Their ID's used in the salespeople's columns.
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40467458
Ok,

The sample is updated to account for that.
Have a look.

You'll add the people table to the query twice (yes! you can do that)
The second instance S_ID in the second people table to Super # in the table you originally referenced
sales-v1.mdb
0
 

Author Closing Comment

by:FFNStaff
ID: 40467542
Nick67, thank you!!  Exactly what I needed.

If you're in the U.S., hope you have a great Thanksgiving!  If not, hope you have a great regular week!
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40467556
Up in the Great White North.
Not as white as Buffalo NY, but there's a foot of snow on the ground and it's 0º F at the moment.
Of course, that's par for the course for late November north of 55º latitude.
Have great Thanksgiving.
Nick67
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro Excel - if condition - Start by AND contain 12 46
Parameter Query 33 51
Delete records based on common identifier from third table 2 31
Can't open Apps in Windows 10 8 69
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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