Results 1 to 14 of 14
  1. #1
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7

    DLookup

    Hi all,

    I have a form named frm_dataentry

    On the form I have a field called Product_Number



    A field called Product_Name

    When the user enters the product number the other field populate using a d look up.

    Code:
    =DLookUp("Product_Name","tbl_Products","Product_Number'")
    This worked okay but now when adding a new record the first product in the products table populates automatically even though the product number field is blank?

    What is the correct code so that the field is blank when no product number is entered?

    many thanks in adavnce

    Chris

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It can all be done with a query as the RecordSource of your form if there is a relationship. You should not need to use DLookup's to complete your form if it is a bound form. Is it?

  3. #3
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7
    Thanks for the reply RuralGuy.

    I have never used access before so I am a complete newbie to it. How do I tell if it's bound? The forms source is the main data table.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What relationship does your MainData table have with the tbl_Products table? Do they both have PrimaryKey fields and are they AutoNumbers?

  5. #5
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7
    They currently have no relationship. The only field that could link the two is Product_Number.

    The primary key field in the products table is the Product_Number field (contains 12,000+ products)

    The primary key on the MainData table is set to a field called form_number - this is taken from the paper forms we use as they have carbon copies.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try using the Relationship window and joining those two tables on the Product_Number field. I assume the MainData table has this value in one of the fields. It is a Text field, right?

  7. #7
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7
    Okay they are now joined. Yes they are text in both tables as alot of the product numbers begin with 0.

    So now I need to create a query to obtain this information from the product_table?

  8. #8
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7
    Okay the forms source is now the query and it works when putting the product number in, it pulls up the product name.

    However when adding the record it doesn't write the product name MainData table?

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Pretty much. Create a query with the query builder and add the two tables to the grid. Because you have defined the relationship, the grid will put in the Join line. You did turn on Referential Integrity right? I do not use cascade updates or deletes as they are simply too powerful and can get you into trouble too quickly. Now bring down the fields you need from *both* tables. You should not be using any Lookup Fields. Are you? http://www.mvps.org/access/lookupfields.htm

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by smidgey View Post
    Okay the forms source is now the query and it works when putting the product number in, it pulls up the product name.

    However when adding the record it doesn't write the product name MainData table?
    You do *not* want that data in more that one table. All that is needed is the [product number]. you can always get the name with a query.

  11. #11
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7
    Ahhhh right! I get you!

    I am using combo box lookups. This is bad??

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    On a form, NO...in a table, YES.

  13. #13
    smidgey is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2011
    Posts
    7
    Okay so I need to correct this in the table. What is the best way to action these? I have one which is a list of members of staff.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922

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

Similar Threads

  1. dlookup help
    By gsantacruz in forum Programming
    Replies: 9
    Last Post: 10-11-2010, 11:46 AM
  2. DLookup()
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 09-15-2010, 07:20 AM
  3. Need help with dlookup.
    By Keith in forum Database Design
    Replies: 8
    Last Post: 05-24-2010, 06:28 PM
  4. Dlookup??
    By Vikki in forum Access
    Replies: 4
    Last Post: 02-16-2010, 07:59 AM
  5. Dlookup
    By janjan_376 in forum Access
    Replies: 20
    Last Post: 07-07-2009, 07:40 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