Results 1 to 7 of 7
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    DLookup Syntax Help

    I'm getting an error with the below DLookup.



    What am I doing wrong?

    Code:
    DLookup("RiskLevelID","tblRiskAssessment","[ProductRiskID]='"& Me.boxDealSummary & "' AND [TransportRiskID]='" & Me.boxTransportSummary & "' AND [TransportArrangementsID]='" & Me.boxTransporting"'")

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    You do not say what the error is?

    I normally associate an ID as numeric?
    Put the criteria into a string variable and Debug.Print that to show what you have, not what you think you have.

    Basics.
    Strings need single quotes surrounding them (unless it has a single quote in it)
    Dates need # surrounding them and in mm/dd/yyyy or yyyymmdd format
    Numerics need no surrounding characters.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Expected = Is the error I am getting.

    Each of the criteria are all numeric.

    Regards

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by Steven19 View Post
    Expected = Is the error I am getting.

    Each of the criteria are all numeric.

    Regards
    So NO single quotes then?

    I *thought* you were just showing the DLookUp code?
    You need to assign the returned value to something?

    Code:
    lngRiskID = DlookUp( ......
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Are you attempting to test this from the immediate window? Then you need to begin with question mark or you will get that error from there also.
    ?DLookup...

    Otherwise, you need to assign the result to something as WGM says.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Also, at the end:

    & Me.boxTransporting & "'")

  7. #7
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Thank you for all your hints and tips, I managed to get it working. So I had two issues.
    1. I didn't assign the DLookUP to something, so thank you WGM
    2. I did not ampersand, thank you Davegri

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

Similar Threads

  1. DLookup Syntax
    By sanderson in forum Forms
    Replies: 11
    Last Post: 09-23-2015, 02:38 PM
  2. DLookup syntax
    By kattatonic1 in forum Forms
    Replies: 3
    Last Post: 07-23-2014, 07:53 AM
  3. dlookup syntax
    By markjkubicki in forum Access
    Replies: 3
    Last Post: 06-25-2014, 06:13 PM
  4. Dlookup syntax
    By crowegreg in forum Programming
    Replies: 2
    Last Post: 03-05-2014, 06:00 PM
  5. dlookup() syntax
    By markjkubicki in forum Programming
    Replies: 4
    Last Post: 08-24-2010, 12: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