Results 1 to 7 of 7
  1. #1
    cihan is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    6

    Dlookup, selecting with variable

    Hello,

    Could anyone help me what is wrong with the following code?

    UNITCAPLOAD = DLookup("[UNITCAPLOAD]", "CSETTINGS", "[TYPEPRODUCT] = "& TYPEPRODUCT &" ")



    It says me syntax error due to missing operator in TYPEPRODUCT.
    TYPEPRODUCT is a string and is found correctly.

    I appreciate your help.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Strings need to be surrounded by quotes:
    "[TYPEPRODUCT]='" & TYPEPRODUCT & "'") - those are single quotes within the double quotes

  3. #3
    cihan is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    6
    How about this one, the criteria is extended with AND statements
    PCURRENT

    UNITCAPLOAD = DLookup("[UNITCAPLOAD]", "CSETTINGS", "[TYPEPRODUCT] = '" & TYPEPRODUCT & "' AND [PCURRENT] = '" & PCURRENT & "' AND [Kv] = '" & Kv & "' AND [CONTACT] = '" & CONTACT & "'")

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Is there something wrong with this? It looks ok, as long as all the fields referenced are strings. Remove the single quotes for numeric.

  5. #5
    cihan is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    6
    I tried this as only TYPEPRODUCT is a string and other parameters are type double
    UNITCAPLOAD = DLookup("[UNITCAPLOAD]", "CSETTINGS", "[TYPEPRODUCT] = '" & TYPEPRODUCT & "' AND [PCURRENT] = " & PCURRENT & " AND [Kv] = " & Kv & " AND [CONTACT] = " & CONTACT & "")

    Here you see the error message
    error1.jpg

  6. #6
    cihan is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2012
    Posts
    6
    See error message:
    Runtime error '3075'
    Syntax error (comma) in query expression '[TYPEPRODUCT]='3DN1' AND [PCURRENT]= 1250 AND [Kv]= 72,5 AND [CONTACT]= 2'.

  7. #7
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    1 - there must be double quotes surrounding the whole string - "[TYPEPRODUCT....=2"
    2 - you are using a comma instead of a dot as a decimal point? Is this the settings on your computer? I'm not sure how Access handles this.
    3 - in your other example - [CONTACT] = " & CONTACT & "") - you don't need the last bit: [CONTACT] = " & CONTACT) - although it doesn't seem to have made any difference

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

Similar Threads

  1. Replies: 2
    Last Post: 03-02-2012, 01:28 PM
  2. DLOOKUP criteria using variable
    By Thumbs in forum Programming
    Replies: 14
    Last Post: 02-21-2012, 08:08 AM
  3. Newbie. How do I use DLookup with a variable please?
    By graffiti in forum Programming
    Replies: 2
    Last Post: 12-12-2011, 08:59 AM
  4. Use a variable in a DLOOKUP?
    By leftylee in forum Forms
    Replies: 9
    Last Post: 07-27-2011, 02:00 PM
  5. Help Using Variable in DLookup Statement
    By bcmarshall in forum Access
    Replies: 9
    Last Post: 12-02-2010, 12:44 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