Results 1 to 4 of 4
  1. #1
    NJMike64 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Posts
    15

    Dlookup driving me crazy

    All,

    It has been a couple of years since I've done db design, but getting back into it for personal needs. I can't recall ever having such a hard time with Dlookup. Here is the code;

    Dim TestE As String
    TestE = DLookup("email", "Employee", "efullnamerev = '" & Forms![frmofficeadd]![PrimName] & "'")
    MsgBox TestE

    In the table related to frmofficeadd, the PrimName is a combo/lookup back to the employee table efullnamerev. When you go into the form you select the name and after update, it should run the above code and set TestE to the email address that is stored in the employee table related to the name.

    Right now, the code keeps returning null.

    If I set the last bit to "efullnamerev = Smith, John'" It returns the email address associated with this name from the employee table.

    Its late and I am sure I am missing something minor here.

    Thanks
    Mike

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I don't use lookup fields in tables but, the last time I checked the value stored in lookup fields it is the index of the lookup that is stored, not the literal text.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Yes, PrimName field probably actually holds the employee ID, not name. Assuming the ID is number type (autonumber field?):

    DLookup("email", "Employee", "ID = " & Forms![frmofficeadd]![PrimName])

    I also never build lookups in tables, especially lookups with alias, just because of this confusion. I prefer to see the actual value, not the alias.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    NJMike64 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Posts
    15
    Thanks to both of you. You called it right on that one. I thought that I was saving a step by doing the lookup in the table, but can see how that will just cause more confusion later. As you both said, it was storing the autonumber and not the literal value.

    Thanks again.

    Mike

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

Similar Threads

  1. Replies: 6
    Last Post: 04-03-2014, 09:04 PM
  2. Too few arguments is driving me crazy....
    By Spidee in forum Access
    Replies: 3
    Last Post: 07-10-2013, 07:41 AM
  3. I know it's easy but it's driving me crazy!!!
    By pensived in forum Queries
    Replies: 1
    Last Post: 02-22-2012, 02:55 AM
  4. ShipToCode is driving me crazy
    By Accessgrasshopper in forum Access
    Replies: 7
    Last Post: 02-26-2011, 04:55 PM
  5. Report issue driving me crazy
    By Grofica in forum Reports
    Replies: 11
    Last Post: 01-28-2011, 11:23 AM

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