Results 1 to 11 of 11
  1. #1
    zylosan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    17

    Problem with DlookUp

    I am using this code

    If IsNull(DLookup("Sku", "tbl_products_and_sku", "Product_ID = " & thisProductId)) Then
    blah blah



    thisPrdouctID is a local string that has been set from another usage of Dlookup and is correctly storing the string variable XP-40R-Y-2-CH. Every time i try to run the function I get the error.

    Run-time error '3075'

    Syntax error (missing operator) in query expression 'Product_ID = XP-40R-Y-2-CH'

    I have tried formatting the query portion of the Dlookup multiple ways and keep getting different errors.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Strings need to be delimited with quotes.

    Try
    Code:
    If IsNull(DLookup("Sku", "tbl_products_and_sku", "Product_ID = '" & thisProductId & "'")) Then

  3. #3
    zylosan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    17
    Which I have already tried based on some sample usage of Dlookup and produces this error

    Run-time error '2471'
    The Expression you entered as a query parameter produced this error: 'Product_ID'

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In table "tbl_products_and_sku", is there a field named "Product_ID"?
    Is it a text type field?

  5. #5
    zylosan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    17
    Yes their is a field name "Product_ID" and its a short text type field.

  6. #6
    zylosan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    17
    I found the error "Product_ID" was actually "Product _ID"

  7. #7
    zylosan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    17
    How do I mark this as solved?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I created a table with the fields "SKU" and "ProductID".
    It has one record:
    SKU : AAABBB
    ProductID : XP-40R-Y-2-CH

    Then I ran this code
    Code:
    Public Sub MyTEstSKU()
       Dim tmp As String
       Dim thisProductId As String
    
    
       thisProductId = "XP-40R-Y-2-CH"
       
    
       tmp = DLookup("Sku", "tbl_products_and_sku", "Product_ID = '" & thisProductId & "'")
       'should return a value
       MsgBox tmp
    
       tmp = IsNull(DLookup("Sku", "tbl_products_and_sku", "Product_ID = '" & thisProductId & "'"))
       'should be false
       MsgBox tmp
    
       'changed string to something not in the table
       thisProductId = "XP-40R-Y-2-CL"
       tmp = IsNull(DLookup("Sku", "tbl_products_and_sku", "Product_ID = '" & thisProductId & "'"))
       'should be true
       MsgBox tmp
    
    End Sub
    The message boxes returned:
    AAABBB
    FALSE
    TRUE


    As far as I can tell, the syntax for DLOOKUP() is correct.
    Something else is causing the error.

  9. #9
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    With Dlookup, Dcount, etc, I always use the braces. Sometimes it keeps Access from getting confused. Try this -
    Code:
    If IsNull(DLookup("[Sku]", "[tbl_products_and_sku]", "[Product_ID] = '" & thisProductId & "'")) Then

  10. #10
    zylosan is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    17
    Thank you both. The dlookup functions correctly now. The problem was that I had a space in my field name where one did not belong. I would like to mark this as solved but I am not sure how to do so.

  11. #11
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Top of page, under "Thread tools"

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

Similar Threads

  1. DLookup problem
    By Paul Netzel in forum Programming
    Replies: 4
    Last Post: 07-14-2013, 12:22 PM
  2. Dlookup Problem
    By sdel_nevo in forum Programming
    Replies: 7
    Last Post: 05-22-2013, 03:05 PM
  3. Dlookup problem
    By Terava in forum Access
    Replies: 5
    Last Post: 04-29-2013, 11:05 PM
  4. VBA DlookUp problem
    By luli in forum Programming
    Replies: 1
    Last Post: 01-06-2013, 09:32 PM
  5. DLookup Problem
    By alsoto in forum Queries
    Replies: 5
    Last Post: 02-23-2012, 12:22 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