Results 1 to 6 of 6
  1. #1
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67

    DLookup and Numerical Values

    Hi,



    Having a problem finding the right syntax for using numerical variables with DLookup. The code I have written, which is throwing up an error 'lngNo', is this:

    lngID = DLookup("CustID", "tblInvoice", "[BookingID] = lngNo")

    lngNo is a long varible, as each time the code is run, the value is likely to be different. If I hard code it thus:

    lngID = DLookup("CustID", "tblInvoice", "[BookingID] = 7")

    then it works fine, but is useless to me. I'm missing something simple here, I know, but at present it's eluding me.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Is lngNo a variable?

    If so, then maybe try:
    lngID = DLookup("CustID", "tblInvoice", "[BookingID] = " & lngNo)


  3. #3
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67
    Yes, thank you, that did the trick.
    That pesky ampersand - now why didn't I think of that!


    Regards, Prof.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yes, if you include the variable name inside the quotes, it is treated as a literal text value, and not a variable.
    So you were literally passing the argument the text "lngNo", instead of the value of the variable lngNo.

  5. #5
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67
    I did try it outside the quotes, as thus:

    lngID = DLookup("CustID", "tblInvoice", "[BookingID]" = lngNo)

    But that just produced a type mismatch error - I couldn't seem to win!

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Very close. The equals sign needs to be within the quotes too.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-08-2012, 08:04 AM
  2. Replies: 5
    Last Post: 06-13-2012, 07:43 PM
  3. Replies: 3
    Last Post: 11-15-2011, 02:41 PM
  4. Combo box not picking up values basis dlookup
    By amangupts in forum Programming
    Replies: 13
    Last Post: 07-15-2011, 11:03 AM
  5. How do I get dlookup values to store in table
    By rpmyhero in forum Access
    Replies: 1
    Last Post: 11-25-2009, 05:57 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