Results 1 to 3 of 3
  1. #1
    Drak is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    22

    The proper way to grab data from a relationship table

    So for so many questions, this is my last post. (I hope ).

    I have a customer table, which holds there information, then I have an orders table. The orders table has a "foreign" key "CustomerID" which is a one-to-many relationship to the primary key in the customer table. Now on my "order" form, the record source being the orders table. I have a combo box filled with the company names. When I select a company, the number (value) the combobox is, is the primary key for the customer table. So I store this found ID in the foreign key in the orders table.



    What exactly is the point of the relationship even existing? I currently use "DLookup()" to pull information from the customer table to display on the order form. (Since the record source is not the costumer table)

    Code:
     Result = DLookup("[Company]","tblCostumer","[ID]=" & Me.CustomerID)
    I feel that I might be doing this wrong, since even if I didn't have that relationship setup, I can still do what I'm doing.

    Sorry for the long explanation.. I have a orders table, which has a relationship to a specific customer. When I'm entering a "new order" how to I "properly" pull information from the costumer table, that the primary id equals the CustomerID. I figured this is where relationships plays a role.
    Last edited by Drak; 01-10-2012 at 06:41 PM.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The primary/foreign key relationship is so that you don't need fields in the Orders table for all the customers info and repeatedly enter this data on each order record. A basic principle of relational database is 'don't repeat data'. So by only saving a key value, all of the customer's related info can be retrieved for display in a form (or a report) by joining the tables in a query and making that query the form/report data source. Domain aggregate functions (DLookup, etc) in queries or in textboxes can make processes slow.

    You could use a form/subform arrangement for the data entry of customer and order, or to find existing customer and add order.

    What you have is a solo form just for order entry with a combobox from which a customer ID is selected. This combobox could be multi-column with the ID field hidden and shows only customer name. If you want to display related customer info (address, etc), the RecordSource for this form can be a query that joins the two tables, join type 'show all order records ...'. Do not allow edit of customer info on this form, set the controls displaying customer info as Locked Yes, TabStop No. If users need to see the customer ID to make sure they have the correct Joe Smith, then that field could also be displayed in a locked textbox.

    In summary, the most efficient method to retrieve related data is by query joins.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Drak is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    22
    Thanks so much. You're the man!

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

Similar Threads

  1. Relationship / ERD according to data
    By nyt1972 in forum Database Design
    Replies: 7
    Last Post: 10-11-2011, 01:08 PM
  2. Grab first characters from field
    By sau3-access in forum Access
    Replies: 1
    Last Post: 10-04-2011, 10:40 AM
  3. grab partial data from one cell
    By andiwir in forum Queries
    Replies: 4
    Last Post: 08-10-2011, 08:55 PM
  4. Ensuring Proper Data Entry
    By skg in forum Forms
    Replies: 5
    Last Post: 01-27-2011, 10:12 PM
  5. Replies: 0
    Last Post: 03-15-2010, 02:38 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