Results 1 to 6 of 6
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    DLookup Add extra Field


    Here is my code for DLookup, I want it to also lookup the Supplier form the same table. Not sure how to add to it!

    DLookUp("UnitPrice","Products","ProductID = " & [ProductID])

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    To clarify, do you want the dlookup() to return both the unitprice and the supplier of the product identified by the productID or do you want to find the unit price based on both the productID and the supplier?

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    I need both. Yes, both based on ProductID..

    Thanks,

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    If you need to pull the unit price based on both the productID and the supplier, the dlookup() would look like the following. This assumes that the supplierID field is a field in the Products table.

    DLookUp("UnitPrice","Products","ProductID = " & [ProductID] & " AND SupplierID=" & [SupplierID])

    However, if you want this:

    DLookUp("UnitPrice_Supplier","Products","ProductID = " & [ProductID])

    That cannot be done in the dlookup() function as you currently have it set up.

    You will have to create a query that concatenates the supplier with the unit price and then reference that field and that query in the dlookup()

    For example, the query might look like this:


    query name: qryUnitPriceWithSupplier
    SELECT unit_price & "_" & supplierID as UnitPriceAndSupplier, productID
    FROM Products

    The Dlookup() would look like this:

    Dlookup("UnitPriceAndSupplier","qryUnitPriceWithSu pplier", "ProductID=" & [ProductID])

    When you do this, the UnitPriceAndSupplier field will no longer be numeric but rather text, so you will not be able to conduct any arithmetic operations with that field.

  5. #5
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    jzwp11 & burrina -

    Actually, and perhaps surprisingly, you CAN include an expression in DLookup!

    A DLookup like this works fine : dlookup("duty_ID * Seq_num","job_statement","Job_Statement_ID = -178426"), and does return a numeric. You can include constants as well.

    Burrina, your Dlookup could look something like this:

    DLookUp("UnitPrice & ' ' & Products","ProductID = " & [ProductID])

    But as jzwp11 pointed out, the result would be a string, and you would have to use more VBA to separate the parts.

    John

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Thanks John--learn something new about Access everyday.

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

Similar Threads

  1. Joining Tables where 1 field has an extra character
    By smoothlarryhughes in forum Queries
    Replies: 5
    Last Post: 12-13-2012, 02:53 PM
  2. Use DLookup to Retrieve Field Value from a Date?
    By Heatshiver in forum Programming
    Replies: 8
    Last Post: 04-06-2012, 10:09 AM
  3. DLookup with multiple field condition
    By agent- in forum Programming
    Replies: 4
    Last Post: 10-15-2011, 05:17 PM
  4. DLookup for Yes/No field
    By Lockrin in forum Access
    Replies: 3
    Last Post: 05-27-2010, 12:03 PM
  5. Extra date field update
    By georgft in forum Forms
    Replies: 0
    Last Post: 09-17-2008, 06:51 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