Results 1 to 10 of 10
  1. #1
    pyromaniac511 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    15

    dlookup returning #Type!

    I have a text field that was returning an ID instead of the represented name so I used
    Code:
    =DLookUp("Brand_Name","tblBrands","Brand_ID = " & [Brand_ID])
    in the control source. It returned #Type!

    I checked myself by using
    Code:
    =DLookUp("Brand_Name","tblBrands","Brand_ID = 2")
    and it returned the name. What am I doing wrong?

    tblBrands
    - Brand_ID
    - Brand_Name

    tblItems


    - Item_ID
    - Brand_ID
    - Model_ID
    - Item_SN
    - Item_Location

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I'd consider this if appropriate:

    BaldyWeb - Autofill

    To make the DLookup() work, I'd double check what the Brand_ID field contained. If it's a combo, it may not be what you see.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It might not be the DLookup itself, but what you are trying to do with it.

    Is the text field (control) bound to a table field? If so, what is the data type of that field?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Oh, and if the textbox has the same name (Brand_ID), change it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pyromaniac511 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    15
    I am assuming it is bound since it is trying to talk to another table but I have no Idea. I changed the textbox name to txtBrandID.

    ... Ok, I just copied the code that didn't work and put in =[Brand_ID] to confirm I was getting a number. I then pasted the failed code in and it worked. Is access always this qwarky?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by pyromaniac511 View Post
    Is access always this qwarky?
    Yes.

    Glad you got it working.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Quote Originally Posted by pyromaniac511 View Post
    I am assuming it is bound since it is trying to talk to another table but I have no Idea. I changed the textbox name to txtBrandID.

    ... Ok, I just copied the code that didn't work and put in =[Brand_ID] to confirm I was getting a number. I then pasted the failed code in and it worked. Is access always this qwarky?
    If you mean by qwarky that Access gets confused when you have a Control on a form and a Field in the Recordset of the same form with the same name than I support Paul's answer. I think I would be confused as well.

  8. #8
    pyromaniac511 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Posts
    15
    Maybe, I'm pretty new to access. In MySQL this wasn't an issue and I grew to like matching my names (obj_ID = obj_ID). It makes remembering what I was thinking easier later on. I would think the way it is structured would prevent any confusion since DLookUp("Brand_Name","tblBrands","Brand_ID") is looking for Brand_ID inside table tblBrands and is oblivious to anything outside that table. [Brand_ID] ... ok I don't know what the brackets mean but figured they had something to do with the local page.

    Are access resources not oblivious to each other?

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Depending on the context [brackets] usually mean a field rather than a control but I believe there are exceptions. Many developers have simply adopted techniques that minimize these sort of issues.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    As to your confusion, the part outside the quotes:

    =DLookUp("Brand_Name","tblBrands","Brand_ID = " & [Brand_ID])

    is not "looking for Brand_ID inside table tblBrands", it's trying to find the value that you want to find within tblBrands. This is the point where Access can get confused, as it tries to find the field/control/variable you've specified.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. DLookup returning #Error
    By apk19 in forum Forms
    Replies: 8
    Last Post: 12-15-2015, 03:26 AM
  2. DLookUp Not Returning Anything
    By Bkper087 in forum Access
    Replies: 5
    Last Post: 04-08-2015, 11:54 AM
  3. Replies: 14
    Last Post: 05-08-2014, 12:51 PM
  4. Dlookup returning #Error
    By ozziestockton in forum Forms
    Replies: 4
    Last Post: 07-30-2012, 10:53 AM
  5. Replies: 1
    Last Post: 10-20-2011, 07:37 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