Results 1 to 5 of 5
  1. #1
    Jishnu Surendran is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2018
    Posts
    29

    DLookup

    I have a function in a query;DLookUp("[Field1]","[Table2]","[Field2]="&[Field2]).

    Field 1 = Value I want to retrieve in Table 2
    Table 2 = Lookup table
    Field 2 = Lookup value in Table 1 which is also in the corresponding row of Field 1 in Table 2

    This function is returning an error.


    Field 1 & 2 are text values.
    Field 2 is a list created from Table 2.

    Help me on this!

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If (since) Field 1 & 2 are text values, you are going to need text delimiters.


    What the DLookup is saying is "Find a record in Table2 where Field2 equals the specified value and return the value from Field1 in table2.

    Lets say there is a form named "Form1" with a text box named "tbText2".
    Then the DLookup would look like:
    Code:
    DLookUp("[Field1]","[Table2]","[Field2] = '" & Forms!Form1.tbText2 & "'")
    You have to concatenate the value to the WHERE clause in the DLookup.



    Field 2 = Lookup value in Table 1 which is also in the corresponding row of Field 1 in Table 2
    Don't really understand what you mean here

    Maybe
    Code:
    DLookUp("[Field1]","[Table2]","[Field2] = '" & NameOfTable1.field2 & "'")
    If this doesn't make sense to you, post the SQL of the query and indicate which fields are to be used.......

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    99 times out of 100 you should be using a join in the query to find these values.

    Add table 2 to your query and join the fields you are trying to match.
    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 ↓↓

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    Hi,

    I agree with Minty, it's a very bad idea to use Dlookup functions in a query. For each result record the query has to do a full table scan of the lookup table without any use of indexes, making the whole query very, very slow.
    Better solve the query using joins.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I agree with Minty and NoellaG.... I my example was just to clarify why your DLookup didn't work.

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

Similar Threads

  1. Shortening if / dlookup >0 / then dlookup
    By Jack Russel in forum Modules
    Replies: 1
    Last Post: 02-19-2016, 03:01 PM
  2. DLookup
    By Alex Motilal in forum Programming
    Replies: 2
    Last Post: 04-20-2015, 11:05 PM
  3. DLookup with value from CBO
    By excellenthelp in forum Access
    Replies: 6
    Last Post: 12-31-2014, 09:11 AM
  4. Using a DLOOKUP
    By derek7467 in forum Access
    Replies: 9
    Last Post: 02-20-2014, 04:07 PM
  5. Dlookup
    By pcandeias0 in forum Programming
    Replies: 3
    Last Post: 07-09-2011, 02:31 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