Results 1 to 6 of 6
  1. #1
    Bkper087 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    81

    DLookUp Not Returning Anything

    Not real sure what I'm doing wrong. I am trying to match the field in [MembershipT]![Rank] to [Description] in [lktPositionCodesT]. I want the [Points] field to be the value shown. When I run this in a query nothing is returned. Any ideas?



    DLookUp("[Points]","[lktPositionCodesT]","[Description]='[MembershipT]![Rank]'")

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure what "lktPositionCodesT" is, but maybe this will help you.

    Three things:
    1) You can't refer directly to a field in a table.
    2) You have to concatenate the value in the function with appropriate delimiters
    3) The DLookup() function will return one value, if found.

    Here is a scenario:
    You had a form named "Members"
    On that form, there is a control named "Rank"
    and you have a control to display the points,

    you would use
    Code:
    DLookUp("[Points]","lktPositionCodesT","[Description]='" & Me.Rank & "'")
    or you could refer to a control on a different form
    Code:
    DLookUp("[Points]","lktPositionCodesT","[Description]='" & Forms!AnotherForm.Rank & "'")

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,738
    It would be easier to understand if you showed us your table design, and some sample data.
    We only know what you tell us and there isn't much to go on here. I hope Steve has guessed correctly, but it is helpful to readers when you tell us about what you're trying to accomplish, the data types involved, and sample data.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Its a simple syntax error, I think - you have [MembershipT]![Rank] inside the quotes, and it should not be.

    Try this:

    DLookUp("[Points]","[lktPositionCodesT]","[Description]='" & [MembershipT]![Rank] & "'")

    (additional character in red). If [MembershipT]![Rank] is numeric, remove the single quotes.

  5. #5
    Bkper087 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    81
    Thanks for the help. ssanfu, your code helped me figure it out. I still don't really understand what is going on with this but it is working now. Partly what confused me is using a single tick mark ' vs a double " in this equation. If anyone cares to explain that part it may help me and others out in the future.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,738
    Text/string values have to be enclosed in quotes.
    So in the example by John

    Code:
    DLookUp("[Points]","[lktPositionCodesT]","[Description]='" & [MembershipT]![Rank] & "'")
    
    The DLookup syntax is http://www.techonthenet.com/access/f...in/dlookup.php

    In John's example the criteria expression is a string:
    So the whole criteria expression has to be enclosed in quotes,
    and because you want the value of MembershipT!Rank to be rendered as a string value
    it has to be within quotes

    "[Description]='" & [MembershipT]![Rank] & "'"
    The single quote after the = sign is the method to put a single quote before the rendered MembershipT!Rank value, and the "'" is the way you add the trailing quote around the rendered MembershipT!Rank.

    By rendered value I mean, Access has to find the named field MembershipT!Rank and then get its value and insert it into your DLookup function.

    For more info on delimiters see
    http://allenbrowne.com/binary/Access...Chapter_07.pdf

    Good luck.

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

Similar Threads

  1. Replies: 10
    Last Post: 12-27-2013, 02:54 PM
  2. Replies: 3
    Last Post: 08-08-2012, 08:04 AM
  3. Dlookup returning #Error
    By ozziestockton in forum Forms
    Replies: 4
    Last Post: 07-30-2012, 10:53 AM
  4. Replies: 1
    Last Post: 10-20-2011, 07:37 AM
  5. Replies: 10
    Last Post: 05-19-2010, 10:34 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