Results 1 to 3 of 3
  1. #1
    jjsande1492 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    38

    Form field lookup based on table name stored in another field

    Hi, everyone.



    I have one simple table:
    ID
    Lookup_Table
    Lookup_ID

    In multiple other tables, I have a field called 'Name'. I want to add a field in a datasheet form that will populate with 'Name' based on the Lookup_ID and the Lookup_Table. In other words, if my record set looks like this:

    ID Lookup_Table Lookup_ID
    1 tbl_Parts 50
    2 tbl_Slots 50

    Then for the first record, I want the field in the form to return the 'Name' of Lookup_ID 50 in tbl_Parts and the second record would return the 'Name' of Lookup_ID 50 in tbl_Slots. The output in the form then looks like this:

    ID Lookup_Table Lookup_ID Name
    1 tbl_Parts 50 Name_Of_ID_50_From_tbl_Parts
    2 tbl_Slots 50 Name_Of_ID_50_From_tbl_Slots


    How can I accomplish this?

    Thanks,
    jj
    Last edited by jjsande1492; 06-19-2018 at 12:32 AM. Reason: Clarification

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    "Name" is a reserved word in Access and should not be used as a name for any object. FName, FirstName, LName, LastName, ProdName, CatName etc would be much better and would also give some insight about the actual data.

    You should be able to populate the third field (Actually it's a text box. Only tables and queries have fields) with the DLookup() function. Might be better to use that as a calculated field in the query that populates the form rather than as the Record Source of a text box on the form.

    For more info on DLookup() see: https://www.techonthenet.com/access/...in/dlookup.php
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    jjsande1492 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    May 2018
    Posts
    38
    Perfect. Thank you.

    Also, thank you for the tip on the reserved word. I have changed them.

    Regards,
    jj

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

Similar Threads

  1. Replies: 3
    Last Post: 05-31-2014, 11:37 AM
  2. Replies: 1
    Last Post: 11-15-2013, 11:42 PM
  3. Replies: 5
    Last Post: 11-01-2012, 09:26 AM
  4. Replies: 5
    Last Post: 06-14-2012, 08:30 AM
  5. Replies: 1
    Last Post: 02-29-2012, 10:13 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