Results 1 to 4 of 4
  1. #1
    mfrey40 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    2

    DLookup in Query

    Hi all,

    I'm a brand new Access user and I'm having a lot of trouble understanding how to correctly program a DLookup expression in a query. I'm entering everything from the user interface. Sorry in advance if this info is already on the web/forums, like I said I'm new and just getting my feet wet.



    Basically, I've got a number of tables in my sandbox database, including:
    'z_Play Data'
    'States'

    'States' contains a list of states with primary keys numbered 1-51 and a list of state abbreviations in the second column.

    'z_Play Data' contains a "DL State" field, with the entries listing the 'State' keys (1-51, each record has only 1 key). I'm trying to create a DLookup in a query that takes the state number for a particular record on the 'z_Play Data' table and looks it up on the 'State' table to return the correct state abbreviation.

    I've come up with the following so far:

    DLookUp("option","States","option_id=8")

    In this formula, "option" is the primary key field on the "States" table. "option_id" is the field that contains all the state abbreviations. When I enter this expression in the query, it returns "DE" which is correct for State #8.

    What do I need to change to get the formula to return the abbreviation for the State ID specified in the "z_Play Data" table?

    Thanks in advance,

    Matt

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    That would be the highly inefficient method. What you want to do is join the two tables in the query. Add both tables to the design grid. If a join is not created automatically (a line between the option_id field in each table), you can create one by clicking/dragging. That enables you to return fields from both tables in your query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    mfrey40 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    2
    Wow that was easy. Thank you so much!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Happy to help, and welcome to the site!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. DLookUp Query across multiple tables
    By karldou in forum Queries
    Replies: 2
    Last Post: 12-19-2011, 02:26 PM
  2. Query with Dlookup
    By mari_hitz in forum Queries
    Replies: 5
    Last Post: 10-14-2011, 09:22 PM
  3. Query Dlookup different fields
    By newwales in forum Access
    Replies: 1
    Last Post: 07-07-2011, 10:13 AM
  4. Dlookup in query using Global variable
    By newwales in forum Access
    Replies: 1
    Last Post: 06-03-2011, 03:47 PM
  5. Replies: 4
    Last Post: 03-05-2010, 09:56 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