473,378 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Populate data based on another table

I am sorry if somebody posted this question before, but I already looked for it and I was not lucky to find it.

I am working with Access 2003 on an Orders Database, to make it simple:

I have two tables, one is TBLCustomers and the other is TBLOrderHeader. Both have the field AgentId, I created a form and I want at the moment the customer is updated, to take the AgentId Value from TBLCustomers and save it to TBLOrderHeader.

The reason I want to have this "duplicate" value, is because at any giving time the agent can change, but I want to keep the history on who was the agent for what order.

My knowledge on VBA and SQL is basic.

Thanks in advance for your help
Mar 28 '07 #1
11 2014
MMcCarthy
14,534 Expert Mod 8TB
What is the metadata of these two tables?

Here is an example of how to post table MetaData :
Table Name=tblBookings
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. Field; Type; IndexInfo
  3. StudentID; Autonumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. LastAttendance; Date/Time
Mar 28 '07 #2
What is the metadata of these two tables?

Here is an example of how to post table MetaData :
Table Name=tblBookings
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. Field; Type; IndexInfo
  3. StudentID; Autonumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. LastAttendance; Date/Time
Thank you for your post, I used documenter to get the metadata, I deleted some fields to keep my post as small as possible.

Expand|Select|Wrap|Line Numbers
  1. Table: TBLCustomers    Page: 1
  2.     Properties
  3.     DateCreated:     05/03/2007 09:23:59 a.m.    DefaultView:     Datasheet
  4.     GUID:     {guid {B8EC568C-0FC8-4A3D-    LastUpdated:     14/03/2007 09:56:18 a.m.
  5.     9CF4-0EBB7229B7A4}}
  6.     NameMap:     Long binary data    OrderByOn:     False
  7.     Orientation:     Left-to-Right    RecordCount:     222
  8.     Updatable:     True
  9.     Columns
  10.     Name    Type    Size
  11.     CustomerNumber    Long Integer    4
  12.     AllowZeroLength:     False
  13.     Attributes:     Fixed Size, Auto-Increment
  14.     CollatingOrder:     English
  15.     ColumnHidden:     False
  16.     ColumnOrder:     1
  17.     ColumnWidth:     Default
  18.     DataUpdatable:     False
  19.     GUID:     {guid {EFB6B257-80C9-42A1-8088-62B4D39F808B}}
  20.     OrdinalPosition:     0
  21.     Required:     False
  22.     SourceField:     CustomerNumber
  23.     SourceTable:     TBLCustomers
  24.     CustomerName    Text    50
  25.     AllowZeroLength:     True
  26.     Attributes:     Variable Length
  27.     CollatingOrder:     English
  28.     ColumnHidden:     False
  29.     ColumnOrder:     Default
  30.     ColumnWidth:     2988
  31.     DataUpdatable:     False
  32.     Description:     CustomerName 
  33.     DisplayControl:     Text Box
  34.     Format:     >
  35.     GUID:     {guid {594FAD97-5D26-483C-82A5-D8B29347C4D6}}
  36.     IMEMode:     0
  37.     IMESentenceMode:     3
  38.     OrdinalPosition:     1
  39.     Required:     False
  40.     SourceField:     CustomerName
  41.     SourceTable:     TBLCustomers
  42.     UnicodeCompression:     True
  43.     AgentID    Long Integer    4
  44.     AllowZeroLength:     False
  45.     Attributes:     Fixed Size
  46.     CollatingOrder:     English
  47.     ColumnHidden:     False
  48.     ColumnOrder:     Default
  49.     ColumnWidth:     Default
  50.     DataUpdatable:     False
  51.     DecimalPlaces:     Auto
  52.     Description:     Asentid Number
  53.     DisplayControl:     Text Box
  54.     GUID:     {guid {435CFD96-A99B-42B5-9855-B8D2447184B0}}
  55.     OrdinalPosition:     7
  56.     Required:     False
  57.     SourceField:     AgentID
  58.     SourceTable:     TBLCustomers
  59.     Relationships
  60.     TBLAgentsTBLCustomers
  61.     TBLAgents    TBLCustomers
  62.     AgentID    AgentID
  63.     Attributes:     Not Enforced
  64.     RelationshipType:     One-To-Many
  65.     TBLCustomersTBLOrdersHeaders
  66.     TBLCustomers    TBLOrdersHeaders
  67.     CustomerNumber    CustomerNumber
  68.     Attributes:     Not Enforced
  69.     RelationshipType:     One-To-Many
  70.     Table Indexes
  71.     Name    Number of Fields
  72.     CustomersAgentID    1
  73.     Clustered:     False
  74.     DistinctCount:     4
  75.     Foreign:     False
  76.     IgnoreNulls:     False
  77.     Name:     CustomersAgentID
  78.     Primary:     False
  79.     Required:     False
  80.     Unique:     False
  81.     Fields:
  82.     AgentID    Ascending
  83.     Number    1
  84.     Clustered:     False
  85.     DistinctCount:     223
  86.     Foreign:     False
  87.     IgnoreNulls:     False
  88.     Name:     Number
  89.     Primary:     False
  90.     Required:     False
  91.     Unique:     True
  92.     Fields:
  93.     CustomerNumber    Ascending
  94.     PrimaryKey    1
  95.     Clustered:     False
  96.     DistinctCount:     223
  97.     Foreign:     False
  98.     IgnoreNulls:     False
  99.     Name:     PrimaryKey
  100.     Primary:     True
  101.     Required:     True
  102.     Unique:     True
  103.     Fields:
  104.     CustomerNumber    Ascending
  105.  
  106. Table: TBLOrdersHeaders    
  107.     Properties
  108.     DateCreated:     15/03/2007 12:41:51 p.m.    DefaultView:     Datasheet
  109.     GUID:     {guid {8954442E-201D-4E59-    LastUpdated:     28/03/2007 09:00:50 a.m.
  110.     84CA-6639F7F51EA9}}
  111.     NameMap:     Long binary data    OrderByOn:     False
  112.     Orientation:     Left-to-Right    RecordCount:     3357
  113.     Updatable:     True
  114.     Columns
  115.     Name    Type    Size
  116.     OrderDate    Date/Time    8
  117.     AllowZeroLength:     False
  118.     Attributes:     Fixed Size
  119.     CollatingOrder:     English
  120.     ColumnHidden:     False
  121.     ColumnOrder:     Default
  122.     ColumnWidth:     Default
  123.     DataUpdatable:     False
  124.     DefaultValue:     =Now()
  125.     Description:     Order Date
  126.     Format:     Short Date
  127.     GUID:     {guid {04E584D1-0383-4937-8103-9245926680E3}}
  128.     IMEMode:     0
  129.     IMESentenceMode:     3
  130.     OrdinalPosition:     0
  131.     Required:     True
  132.     SourceField:     OrderDate
  133.     SourceTable:     TBLOrdersHeaders
  134.     NumberOrder    Long Integer    4
  135.     AllowZeroLength:     False
  136.     Attributes:     Fixed Size, Auto-Increment
  137.     CollatingOrder:     English
  138.     ColumnHidden:     False
  139.     ColumnOrder:     Default
  140.     ColumnWidth:     Default
  141.     DataUpdatable:     False
  142.     Description:     Number de la Order
  143.     GUID:     {guid {55022CF9-DFB9-456B-8B01-85C17D093167}}
  144.     OrdinalPosition:     1
  145.     Required:     False
  146.     SourceField:     NumberOrder
  147.     SourceTable:     TBLOrdersHeaders
  148.     CustomerNumber    Long Integer    4
  149.     AllowZeroLength:     False
  150.     Attributes:     Fixed Size
  151.     CollatingOrder:     English
  152.     ColumnHidden:     False
  153.     ColumnOrder:     Default
  154.     ColumnWidth:     Default
  155.     DataUpdatable:     False
  156.     DecimalPlaces:     Auto
  157.     Description:     Customer Number 
  158.     DisplayControl:     Text Box
  159.     GUID:     {guid {72EF6728-1B7A-4821-8535-634FB3507CA4}}
  160.     OrdinalPosition:     2
  161.     Required:     False
  162.     SourceField:     CustomerNumber
  163.     SourceTable:     TBLOrdersHeaders
  164.     AgentID    Long Integer    4
  165.     AllowZeroLength:     False
  166.     Attributes:     Fixed Size
  167.     CollatingOrder:     English
  168.     ColumnHidden:     False
  169.     ColumnOrder:     Default
  170.     ColumnWidth:     Default
  171.     DataUpdatable:     False
  172.     DecimalPlaces:     Auto
  173.     Description:     Agent ID
  174.     DisplayControl:     Text Box
  175.     GUID:     {guid {6F015A46-DA9B-4712-9CFA-E8D3ACA0A136}}
  176.     OrdinalPosition:     3
  177.     Required:     False
  178.     SourceField:     AgentID
  179.     SourceTable:     TBLOrdersHeaders
  180.     Relationships
  181.     TBLAgentsTBLOrdersHeaders
  182.     TBLAgents    TBLOrdersHeaders
  183.     AgentID    AgentID
  184.     Attributes:     Not Enforced
  185.     RelationshipType:     One-To-Many
  186.     TBLCustomersTBLOrdersHeaders
  187.     TBLCustomers    TBLOrdersHeaders
  188.     CustomerNumber    CustomerNumber
  189.     Attributes:     Not Enforced
  190.     RelationshipType:     One-To-Many
  191.     Table Indexes
  192.     Name    Number of Fields
  193.     AgentID    1
  194.     Clustered:     False
  195.     DistinctCount:     1
  196.     Foreign:     False
  197.     IgnoreNulls:     False
  198.     Name:     AgentID
  199.     Primary:     False
  200.     Required:     False
  201.     Unique:     False
  202.     Fields:
  203.     AgentID    Ascending
  204.     CustomerNumber    1
  205.     Clustered:     False
  206.     DistinctCount:     228
  207.     Foreign:     False
  208.     IgnoreNulls:     False
  209.     Name:     CustomerNumber
  210.     Primary:     False
  211.     Required:     False
  212.     Unique:     False
  213.     Fields:
  214.     CustomerNumber    Ascending
  215.     NumberOrder    1
  216.     Clustered:     False
  217.     DistinctCount:     3357
  218.     Foreign:     False
  219.     IgnoreNulls:     False
  220.     Name:     NumberOrder
  221.     Primary:     False
  222.     Required:     False
  223.     Unique:     True
  224.     Fields:
  225.     NumberOrder    Ascending
  226.     PrimaryKey    1
  227.     Clustered:     False
  228.     DistinctCount:     3357
  229.     Foreign:     False
  230.     IgnoreNulls:     False
  231.     Name:     PrimaryKey
  232.     Primary:     True
  233.     Required:     True
  234.     Unique:     True
  235.     Fields:
  236.     NumberOrder    Ascending
Mar 28 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
That was a little too long for most experts to trawl through. Is this an accurate representation of the table structures.

Table Name=TBLCustomers
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. CustomerNumber; Long Integer; PK and FK (to PK of TBLOrdersHeaders)
  3. CustomerName; String; 
  4. AgentID; Long Integer; FK (to PK of TBLAgents)
  5. CustomersAgentID;  Long Integer; FK (to PK of TBLCustomersAgents)
  6.  
Table Name=TBLOrdersHeaders
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. NumberOrder; LongInteger; PK    
  3. OrderDate; Date/Time
  4. CustomerNumber; Long Integer; FK (to PK of TBLOrdersHeaders)
  5. AgentID; Long Integer; FK (to PK of TBLAgents)
  6.  
Mar 29 '07 #4
That was a little too long for most experts to trawl through. Is this an accurate representation of the table structures.

Table Name=TBLCustomers
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. CustomerNumber; Long Integer; PK and FK (to PK of TBLOrdersHeaders)
  3. CustomerName; String; 
  4. AgentID; Long Integer; FK (to PK of TBLAgents)
  5. CustomersAgentID;  Long Integer; FK (to PK of TBLCustomersAgents)
  6.  
Table Name=TBLOrdersHeaders
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. NumberOrder; LongInteger; PK    
  3. OrderDate; Date/Time
  4. CustomerNumber; Long Integer; FK (to PK of TBLOrdersHeaders)
  5. AgentID; Long Integer; FK (to PK of TBLAgents)
  6.  
Yes, it is.

Thank you
Mar 29 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
OK AgentID should not be in both of these tables because this is duplicate information. If a customer always has the same agent then leave it in the TBLCustomers. If the agent can change per order then leave it in TBLOrdersHeaders. But it should only be in one of these tables and not both of them.

Mary

Table Name=TBLCustomers
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. CustomerNumber; Long Integer; PK
  3. CustomerName; String; 
  4. AgentID; Long Integer; FK (to PK of TBLAgents)
  5. CustomersAgentID;  Long Integer; FK (to PK of TBLCustomersAgents)
  6.  
Table Name=TBLOrdersHeaders
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. NumberOrder; LongInteger; PK    
  3. OrderDate; Date/Time
  4. CustomerNumber; Long Integer; FK (to PK of TBLCustomers)
  5. AgentID; Long Integer; FK (to PK of TBLAgents)
  6.  
[/quote]
Mar 29 '07 #6
OK AgentID should not be in both of these tables because this is duplicate information. If a customer always has the same agent then leave it in the TBLCustomers. If the agent can change per order then leave it in TBLOrdersHeaders. But it should only be in one of these tables and not both of them.

Mary

Table Name=TBLCustomers
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. CustomerNumber; Long Integer; PK
  3. CustomerName; String; 
  4. AgentID; Long Integer; FK (to PK of TBLAgents)
  5. CustomersAgentID;  Long Integer; FK (to PK of TBLCustomersAgents)
  6.  
Table Name=TBLOrdersHeaders
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. NumberOrder; LongInteger; PK    
  3. OrderDate; Date/Time
  4. CustomerNumber; Long Integer; FK (to PK of TBLCustomers)
  5. AgentID; Long Integer; FK (to PK of TBLAgents)
  6.  
[/quote]

Mary,

Thank you for your answer. I know the information is "duplicated" but as it is time critical, I need to record at order level who the agent was, because the customers table indicate the current situation, but I want to keep history at order level.

i.e. Today for customer A the agentID is 1, two months from now the agentID could be 2, but I want to keep the sales history for agent 1, I can't ignore previous sales

Thanks,
Mar 29 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
When adding a record by form to TBLOrderHeaders, put the following in the After Update event of the CustomerNumber textbox:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CustomerNumber_AfterUpdate()
  2.  
  3.    Me!AgentID = DLook("[AgentID]", "TBLCustomers", "[CustomerNumber]=" & Me!CustomerNumber
  4.  
  5. End Sub
  6.  
This assumes CustomerNumber is a Number fieldtype and not a text field.

Mary
Mar 29 '07 #8
I Hate to but in, as I am no expert.

But is this not a case where you would want another table of agents. And one field in each of the other tables that point to the agents table?
Mar 29 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
I Hate to but in, as I am no expert.

But is this not a case where you would want another table of agents. And one field in each of the other tables that point to the agents table?
Based on the metadata that was posted this is the case. There is a table called TBLAgents.

Never be afraid to butt in. That's how we all learn and you were right. :)
Mar 29 '07 #10
Based on the metadata that was posted this is the case. There is a table called TBLAgents.

Never be afraid to butt in. That's how we all learn and you were right. :)
Mary,

Thank you very much for your valuable help.
Mar 30 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Mary,

Thank you very much for your valuable help.
You're welcome!
Mar 30 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
7
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data...
3
by: Chifo | last post by:
hello. i have a problem with a populate html table with data from table here it's the problem two querys retrieving data from table, one of querys show me a colletion of data from 6:00 am to...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
1
by: dmeyr | last post by:
Hello, I am new to Access and am having difficulty with a Dlookup function. I have a form that I wish to autopopulate 10 fields with values based on two criteria which are also fields on the form....
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
4
by: Nate | last post by:
I am looking to populate a Schedule table with information from two other tables. I am able to populate it row by row, but I have created tables that should provide all necessary information for me...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
2
by: toofunny24 | last post by:
I have two tables and both have identical fields for the most part. Both tables are linked by product id. One table is used for entering actual data. Table two contains the specs/target numbers...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.