Results 1 to 8 of 8
  1. #1
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42

    DLookUP problem

    I have a slight problem understanding the DLookup Method (I think it's a method :P)

    I am not completely new to programming but I am self-taught so... couple of things lacking in my head.

    I have 2 tables, 1st : Product table, 2nd Cost of those products

    Both tables have SKU fields

    In the Cost table whenever the user adds a new record (which must contain a SKU) the said SKU must be a valid SKU in the Product table.



    I THINK I must use the :
    Private Sub SKU_LostFocus()

    Then use the dlookup to check if the SKU exists in the SKU field of the product_table

    But I am unsure.
    Help would be really appreciated. I have tried to read the Dlookup method on Microsoft's website without any result
    And sorry for my english

    Feel free to ask questions I'll try to answer as fast as possible.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can make your SKU field a Combo Box field, using the SKUs from your Product field as its Control Source.
    Then the user would be selecting the SKU from a drop down list, and you can prevent them from adding codes that do not exist.

  3. #3
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    It works like a charm. Thank you very much for this. I would still like to understand the Dlookup if anyone could explain it to me. (For future reference)

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    There is another write-up here, which may be a little simpler:
    http://www.techonthenet.com/access/f...in/dlookup.php

  5. #5
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    I think it's the Criteria part I am having troubles with. let's say dlookup("SKU", "product_table", "SKU = the_name_of_the_text_box"). My dlookup is always NULL whatever I insert in the textbox I am trying to compare to my main database.

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you include the name of the Text Box inside quotes, it is treated as a literal and not a variable. I think you want something like this:
    Code:
    Dlookup("SKU", "product_table", "SKU = '" & Me.the_name_of_the_text_box & "'")

  7. #7
    Symlink is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    42
    Yeppppp.... I am stupid :P thanks for this

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Don't feel bad. Its actually very common issue with new programmers, understanding the difference between literals and variables.

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

Similar Threads

  1. VBA DlookUp problem
    By luli in forum Programming
    Replies: 1
    Last Post: 01-06-2013, 09:32 PM
  2. DLookup Problem
    By alsoto in forum Queries
    Replies: 5
    Last Post: 02-23-2012, 12:22 PM
  3. DLookup problem
    By the_rock in forum Programming
    Replies: 3
    Last Post: 01-11-2012, 02:36 AM
  4. Dlookup problem
    By metronometro in forum Queries
    Replies: 1
    Last Post: 01-07-2012, 12:17 PM
  5. Using Dlookup problem
    By Lupson2011 in forum Access
    Replies: 5
    Last Post: 12-07-2011, 10:33 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