Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    stevekroll is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    16

    Question Including First and Last Name fields from one table into lookup in other table


    I am trying to use the first name and last name fields from one table into a lookup field - Full Name of another table. When I did this, it showed both first and last names in the lookup selection, but they were separated by a column. I could only select the first name. Should I create a query of the source table including the first and last name fields? Could I select the first and last names of the query to be used in the one field Full Name in the Lookup in the other table.

    I am a new access user, so please forgive me if this has been covered before. If there is another thread that answers this question, please let me know. Thanks..Steve

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    A basic rule is that lookup fields in tables are a bad idea. Use a combobox control on a form and either use a table or a value list as the RowSource for the combobox control

    I am not sure what you are asking about. It seems as though you want to duplicate data from one table and store it in another.

    The best way would be to retrieve the first an last name from the original table, using a query. If you need to associate a record in another table you should use a unique identifier (Primary Key) from the original table and store that value in the relative table/record (using a Foreign Key field).

    Create relationships (Joins) between tables using number values. Primary Key fields joined ON Foreign Key fields is a standard practice.

  3. #3
    stevekroll is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    16
    I have a staff table which includes first and last name fields. I have another table called Allocation which is to allocate time spent by staff members to specific programs. So the Allocation table would include ID, full name field (need first & last names), allocation % field, and program ID. Each staff member's time can be allocated to multiple program IDs. Each record would contain the unique combination of full name, allocation %, and program ID. Eventually, I would sum the allocation % field per program ID for each staff member in a query or report. So I wanted the full name field in the allocation table to be a lookup where I can select both first and last names for the full name field.

    Thanks for replying. I appreciate your help.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Further to ItsMe comments and suggestions, I'm going to point you to a link that will show you how to design your tables.
    You'll have to read and work through the tutorial, but you will learn.

    Good luck. Let us know how you made out. And welcome to Access and this forum!

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    For now, I am going to stay on point of retrieving the first and last name. It is ideal to store the first name in its own field/column and the last name in its own name/column, as you have it now.

    From a combobox, from a query, display it in a form, etc. does not matter how the user interacts with the database. It is preferable to concatenate fields together.

    You can create a RowSource for a combobox this way

    SELECT FieldID, FirstName & " " & LastName AS FullName FROM tblEmployees

    This simple SQL statement can be applied in different ways. It concatenates two fields and creates an alias with the results. The alias can be used instead of creating and storing redundant data in tables. The alias is created, held in memory, and destroyed after use.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    An alternative for the combobox RowSource is:

    SELECT EmpID, LastName & ", " & FirstName AS FullName FROM tblEmployees ORDER BY LastName, FirstName;

    Other combobox properties:

    ControlSource: employee ID foreign key field from Allocations table
    BoundColumn: 1
    ColumnCount: 2
    ColumnWidths: 0";2.0"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    stevekroll is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    16
    From a step-by-step approach, is this what I should do to achieve Full Name in the lookup table Allocation? I realize later a form will be used to enter this, but for now just want to get the info into the database quickly. Unfortunately, I don't have Access to work with until tomorrow.

    Step 1 - Create a query from the employee table which includes first and last name fields.
    Step 2 - In Allocation table, for Employee full name field lookup, select the just created query above.
    Step 3- In RowSource of the lookup, type in Select FieldID, FirstName & " " & LastName as FullName FROM tblEmployees.

    When I go to FullName in the Allocation table, I should see a list of concatenated full names to select one from?

    Right now I just trying to populate this fairly small database - get the data input right, create useful queries, then create useful reports, and then do the input forms. My first stumbling block has been this so far. I am using the Access 2010, The Missing Manual to get me going.

    I greatly appreciate your assistance.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by stevekroll View Post
    ...Right now I just trying to populate this fairly small database....
    You do not need a lookup field. Save Primary Key values from the parent table into a Foreign Key field in the child table. There is not a need to duplicate data such as the FirstName field in child tables. If you tell Access what a given PK value is for a specific record, Access will be able to retrieve the necessary data for you. That is how an RDBMS works.

    You will need a form to populate your tables in the correct way.

  10. #10
    stevekroll is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    16
    Unfortunately, foreign key isn't defined in the book I am using. Primary key is defined.

    The two tables are:

    Employee Staff

    1) ID(primary key)
    2) First Name
    3) Last Name
    4) Department
    5) Titile

    Allocation
    1) ID (primary key)
    2) Allocation %
    3) Employee ID
    4) Program ID(from Program Table)

    In the Allocation table, I wanted a lookup in Employee ID to select Full Name of the employee. Since First Name and Last Name are separate fields in the Employee Table, I needed to concatenate them to form the full name in order to select it. I would then allocate a % to that full name employee associated with the program Id they are working on. An employee can be allocated to many program ids.

    So given this table setup, what primary key from the Employee Table are you suggesting that gets saved into which foreign key field in the Allocation table?

    I do realize I will need a form, but thought I could start with just getting these few tables populated since there isn't a lot of data and run some meaningful queries first before building the forms.
    Last edited by stevekroll; 02-02-2014 at 11:16 AM. Reason: Meant Employee Staff Table Name, not Program Staff

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The Employee ID field of Allocation table is the foreign key and this should be populated with ID from Program Staff table. Program ID would save the ID from Programs table.

    If you set Lookup on field in the table, it will show the name but what is actually saved is the ID value. I don't set lookups in table, especially if it involves an alias. I prefer to see the actual field value.

    Also, recommend no spaces or special characters/punctuation (underscore is exception) in naming convention. Better would be AllocationPct or Allocation_Pct.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    stevekroll is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    16
    Yes, EMPId is FK in Allocations Table. Thanks. Are the steps taken correct? Please see my last post.

  13. #13
    stevekroll is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    16
    I did use the ID field from Employee Table(program staff was wrong) as the link(foreign key) to the Allocation Table Employee Id field. But will that step alone populate the Employee ID with their full name from the two separate fields of first and last name from the Employee Table? The person who will be inputting the Allocation Table needs to be able to see the full name in order to make sure they are assigning the right person.

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Steve,

    Unfortunately, foreign key isn't defined in the book I am using. Primary key is defined.
    Work through this tutorial --- get a different book OR make use of Google/Bing

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You still miss the point. This will not (and should not) populate Allocations table with the employee name, only the ID. Users will see the full name in the combobox RowSource as well as in the table field because of the lookup but the actual value saved is the ID.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 07-25-2013, 11:34 PM
  2. Replies: 3
    Last Post: 06-28-2013, 01:59 PM
  3. No lookup fields at table level then what?
    By justgeig in forum Database Design
    Replies: 3
    Last Post: 06-05-2012, 11:29 AM
  4. Importing into Table with Lookup Fields
    By Fstrategic in forum Import/Export Data
    Replies: 7
    Last Post: 02-16-2012, 05:26 AM
  5. Lookup table combining 2 fields
    By jhoff in forum Access
    Replies: 1
    Last Post: 07-27-2011, 09:31 AM

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