Results 1 to 4 of 4
  1. #1
    sockswithsandals is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    7

    DLOOKUP two tables in query

    Have to ask for help, been stuck for too long...



    I have two tables tblPersonnel and tblCosts. I'm trying to make a query which would return list of names from tblPersonnel and next to the names would return Cost from tblCosts based on country id. CountryID is pk in tblCosts and fk in tblPersonnel. Cost is numeric value but countryid text string.

    This is what I got but it returns an error:

    SELECT tblPersonnel.PerID, DLookUp("Cost","tblCosts","CountryID=" & tblPersonnel.CountryID) AS Expr1
    FROM tblPersonnel;

    Error message:

    the expression you entered as a query parameter produced this error: the object doesn't contain the automation object xxxx

    How this syntax should go?



    EDIT: Yes, got it to work. Correct syntax:

    SELECT tblPersonnel.PerID, DLookUp("Cost","tblCosts","[CountryId] ='" & [tblPersonnel].[countryId] & "'") AS Cst
    FROM tblCosts INNER JOIN tblPersonnel ON tblCosts.CountryId = tblPersonnel.CountryId;

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You would not need the DLookup(). You would include both tables in the query with the join for the countryID (I assume that the datatype of the CountryID field in both tables is the same).

    SELECT tblPersonnel.PerID,tblCosts.Cost
    FROM tblPersonnel INNER JOIN tblCosts ON tblPersonnel.CountryID=tblCosts.CountryID

  3. #3
    sockswithsandals is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    7
    Thanks a lot! Don't understand how I missed that one, it's so simple solution but works perfectly. Thanks!

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome

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

Similar Threads

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