Results 1 to 5 of 5
  1. #1
    RJB is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    9

    DLookup not working

    I'm trying to use the DLookup function to return a value in a form from a table that is different from the table the form is created from.

    Original Table is called: CT Armed Forces
    Form is called: SAD - Create Order
    The other table is called: Base Pay

    Based on the individual's grade, I am trying to have it return the correct base pay for that grade.
    Here is what I have:

    =DLookUp("[Pay Grade]","[Base Pay]","[Pay Grade] = " & [Forms]![SAD - Create Order]![Grade])

    "Pay Grade" is the Field Name in the "Base Pay" Table
    "Grade" is the Field Name is the Field Name in the Form and the "CT Armed Forces" table.



    What I get is the message"#Error" flashing repetitively.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If grade is a text field then you'll need to escape it with quotes , and you don't need the full form reference assuming Grade is a control on your form;

    Code:
    =DLookUp("[Pay Grade]","[Base Pay]","[Pay Grade] = '" & me.Grade &"'")
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    is "[Pay Grade]" numeric. If so, yours is correct,
    if it is string then you must have quotes,

    =DLookUp("[Pay Grade]","[Base Pay]","[Pay Grade] = '" & [Forms]![SAD - Create Order]![Grade] & "'" )

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Note: having spaces, punctuation or special characters (exception is the underscore) in object names is considered bad programming practice.


    Examples
    --------------------------
    Bad Object Name
    Better Object Names
    CT Armed Forces CTArmedForces or CT_ArmedForces or CT_Armed_Forces
    SAD - Create Order SADCreateOrder or SAD_CreateOrder or SAD_Create_Order
    Base Pay BasePay or Base_Pay
    Pay Grade PayGrade or Pay_Grade

  5. #5
    RJB is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    9

    Thanks

    This worked. Thank you

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

Similar Threads

  1. WTF? DLookup not working...
    By dniezby in forum Programming
    Replies: 17
    Last Post: 03-26-2017, 04:05 PM
  2. DLookup not working
    By Lou_Reed in forum Access
    Replies: 29
    Last Post: 03-13-2017, 01:25 PM
  3. DLookup not working,HELP!!
    By riocobre in forum Access
    Replies: 2
    Last Post: 03-12-2017, 11:36 AM
  4. Dlookup not working
    By shaunacol in forum Forms
    Replies: 8
    Last Post: 06-12-2015, 09:28 AM
  5. DLookup isn't working
    By cec in forum Access
    Replies: 7
    Last Post: 12-28-2012, 12:21 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