Results 1 to 6 of 6
  1. #1
    tariq1 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    16

    DLOOKUP function

    Hi,



    I have an Employees Form, with fields including:

    1) EmployeeNumber
    2) FirstName
    3) Notes

    I am learning the DLOOKUP function and am trying to retrieve the FirstName within the Notes field.

    There are 10 records within the Form:
    1) EmpoyeeNumber = 27495 FirstName = Justine
    2) EmployeeNumber = 28404 FirstName = Raymond

    And within the Controlsource of the Notes field I have used
    =DLookUp("FirstName","Employees","EmployeeNumber = [EmployeeNumber] ")

    For 1) Notes = Justine which is correct BUT
    2) Notes = Justine which is incorrect as this should retrieve Raymond

    Thank you for your assistance

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Why are you duplicating the data in the notes field?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    tariq1 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    16
    Hi Bob,

    Thabk you for your response
    I am learning the DLOOKUP functin so am just testing this out with something simple, thats all...

    Tariq

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    =DLookUp("FirstName","Employees","EmployeeNumber = " & [EmployeeNumber])
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    And since this is a learning exercise, a couple of things:

    First, Bob's syntax is correct if 'EmployeeNumber' is defined as a Number Datatype, which your initial post would seem to suggest.

    But if 'EmployeeNumber' were to be defined as a Text Datatype, the correct syntax would be

    Code:
    =DLookUp("FirstName","Employees","[EmployeeNumber] ='" & [EmployeeNumber] & "'")

    Secondly, that 'digits' and 'numbers' should not be confused. Data like Employee Numbers, Serial Numbers, Social Security Numbers, etc., when only containing digits, can be defined as Text or Number Datatypes. Which you elect to use is up to you. The rule of thumb that I use is that if the data will not be used in performing math, it's Text, otherwise, it's a Number. But that's an individual decision. The only I'd define a non-math, all-digits Field as a Number would be if it were to be used as a Primary Key.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    uncletreetrunk is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2012
    Posts
    72
    I had a DLookUp related question yesterday. pbaldy provided this link. It has proper syntax for various data types.

    http://access.mvps.org/access/general/gen0018.htm


    Hope it helps

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

Similar Threads

  1. DlookUp Function.
    By cap.zadi in forum Forms
    Replies: 11
    Last Post: 09-22-2011, 12:56 PM
  2. using the and function in a dlookup statement
    By englisap in forum Programming
    Replies: 10
    Last Post: 01-10-2011, 09:53 PM
  3. Format in Dlookup function
    By tpcervelo in forum Forms
    Replies: 6
    Last Post: 10-22-2010, 10:23 AM
  4. dlookup function problem
    By bdaniel in forum Programming
    Replies: 3
    Last Post: 04-26-2010, 05:55 AM
  5. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 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