Results 1 to 7 of 7
  1. #1
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150

    Dlookup


    Hi

    Code:
     
    myValue = InputBox("Please Enter Lecturer ID")
    sql = DLookup("Lecturer_Name", "Lec_Details", Lecturer_ID = myValue)
    i tried above dlookup function, but its not working. Appreciate your help on this matter.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Maybe:
    Code:
    myValue = InputBox("Please Enter Lecturer ID")
    sql = DLookup("Lecturer_Name", "Lec_Details", "Lecturer_ID = myValue")
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    myvalue must be outside the quotes to resolve, while field name is inside:

    sql = DLookup("Lecturer_Name", "Lec_Details", "[Lecturer_ID] = " & myValue)

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by ranman256 View Post
    myvalue must be outside the quotes to resolve, while field name is inside:

    sql = DLookup("Lecturer_Name", "Lec_Details", "[Lecturer_ID] = " & myValue)
    That's what I thought but before posting I looked up the syntax at: https://www.techonthenet.com/access/...in/dlookup.php where it says:
    Syntax

    The syntax for the DLookup function varies depending on what datatype you are uisng in the last parameter. Below we show how to use the DLookup function with numeric, string, and date value in the final parameter.
    Numeric

    DLookup("FieldName" , "TableName" , "Criteria = n")
    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    That syntax only applies where a specific number value is specified. For example
    Code:
    sql = DLookup("Lecturer_Name", "Lec_Details", "Lecturer_ID = 5")
    However as the input box value is being passed to a variable, myValue, this IS correct for a number field
    Code:
    myValue = InputBox("Please Enter Lecturer ID")
    sql = DLookup("Lecturer_Name", "Lec_Details", "Lecturer_ID = " & myValue)
    OR for a text field
    Code:
    sql = DLookup("Lecturer_Name", "Lec_Details", "Lecturer_ID = '" & myValue & "'")
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by ridders52 View Post
    That syntax only applies where a specific number value is specified. For example
    Code:
    sql = DLookup("Lecturer_Name", "Lec_Details", "Lecturer_ID = 5")
    Thanks Colin. At least I'm no longer confused although I am rather surprised that TechOnTheNet don't show the correct solution for this scenario which I would think is the most common.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    Hi Bob
    I agree totally. Had assumed there was a follow-up page to include the use of variables but that seems not to be the case

    As is so often the case, Allen Browne does it better: http://allenbrowne.com/casu-07.html
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. dlookup with iif
    By pcc in forum Programming
    Replies: 9
    Last Post: 01-16-2018, 02:30 PM
  2. Shortening if / dlookup >0 / then dlookup
    By Jack Russel in forum Modules
    Replies: 1
    Last Post: 02-19-2016, 03:01 PM
  3. DLOOKUP help please
    By goddo2305 in forum Access
    Replies: 5
    Last Post: 05-28-2014, 03:41 AM
  4. dlookup
    By ali zaib in forum Access
    Replies: 3
    Last Post: 01-13-2012, 11:57 AM
  5. DLookup Help
    By Alex Motilal in forum Queries
    Replies: 3
    Last Post: 01-17-2011, 02:01 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