Link to home
Start Free TrialLog in
Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on

Access 2013 Populating a field

Folks,
In my database I have four tables, table1, table2, table3, table4
In table1 three of the fields needs data from tables 2 - 4. Now, for example, in table1 data is needed from any of the other tables and the data has not been entered in a supporting table I would like to add data to the table missing the data so I can have it in table1.
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Are you sure you have designed this system correctly?

In a true relational database, you create relationships between the tables.
In this way you can create a query that contains data form both tables.

In other words, there should be no real need to "Populate" or "add" data from one table to another...

Can you take a step back and provide an overview of your database here?
Avatar of Frank Freese

ASKER

Here's the current Relationship diagram:
User generated imageSome SQL statements can have multiple purposes, clauses and syntaxes
I'm not saying your wrong and indeed this design may be incorrect.
Some SQL statements can have multiple purposes
By your design, ...do you mean this to say:
Some SQL *Keywords* can have multiple purposes?

Yes, ...In this case tblPurpose could have multiple entries (Records) for each Keyword.
So this might be a better staring point:

tblKeyword
kwID (Primary Key)
kwKeyWord

tblPurpose
pID (Primary Key)
p_kwID (Foreign Key)
pText

Data, Main/sub form, and relationships, might look like this:
User generated image
Now you could make a query like this:
SELECT tblKeywords.kwID, tblKeywords.Keyword, tblPurpose.pID, tblPurpose.pPurpose
FROM tblKeywords INNER JOIN tblPurpose ON tblKeywords.kwID = tblPurpose.p_kwID;

To display this:
User generated image
Not here that there is no need to "populate" the Keywords table with the data form the Purpose table...

;-)

JeffCoachman
Well, you might as well just have the sample DB I made..., I have attached it...
;-)

You could probably apply the same design principle to the other child tables...
(and note that my sample was quick and dirty, ...you would probably want to make autonumber fields for your tables primary keys, ...and otherwise tidy up the basic design)

But to be on the safe  side, ...lets see what other experts might post...
;-)

JeffCoachman
Database124.mdb
Thanks Jeff
I don't think we're on the same page yet though. It's been a while since I worked with Access but I do recall that in using a form and there was not a value you were looking for in another table via a combo box one could automatically add the value to the lookup table without closing your form, going to the other table, adding the missing data then returning to the original form to add the data missing.
Not sure I understand either...

Can you express this in terms of an actual user scenario...
I'll try
I have a form frmSQLKeyword that is used to capture information into tblSQLKeyword. All  the information (except Keyword) will come from the three supporting tables, tblSyntax, tblPurpose and tblClause. If, for example, I am entering in a new record into tblSQLKeyword. I come to find out that I need a new Clause because the Clause I need has not been entered into tblClause. I'd like to enter the new Clause (frmClause) and return back to my form and refresh the combo box on my frmSQLKeyword Hope this helps.
Then here is the flow...
(I am not sure on what you are considering a "clause", so I will refer to Keywords and Purposes)
The relationship between Keyword and Purpose is One-To-Many (One keyword can have many Purposes)
You create a Main form of KeyWords (and also a subform of Purposes)
On this main form you have a combobox that lists the keywords
The combobox allows you to select a keyword from the combobox and display the info (and the child data) on the form.
On this main form you click on the "New Record" button and enter a new keyword.
When you click in the subform (to enter a Purpose for this new Keyword), ...the AfterInsert event of the main form triggers, and you requery the combobx:
   me.cboKeyWord.Requery
The combobox is refreshed and the new Keyword appears in the combobox immediately
(You would also add the requery code to the After Delete event of the main form to avoid "Deleted" errors)
...Finally note that you should enforce referential Integrity when you create your relationships.

Hope this helps.
New sample is attached.
;-)

JeffCoachman
Database124.mdb
We're almost there. Now if the information I need is not in the "child" table how can I add the new data to the "child" from the "parent?
Still confused...
You only add the Linking field value from the parent table to the child table, ...that is what the subform does...

In the one to many relationship data only flows from the parent to the child (via the linking field), ...not the other way around.

If we again, reference a standard One to Many relationship of Customers and Orders...
The CustID from the Customer table is inserted into the child table.
There are no references whatsoever to the child table in the Parent table.
For example: there is no reference to the OrderDate (child table) in the Customer table
...because we would not know what order the order date references...

When you say:
if the information I need is not in the "child" table how can I add the new data to the "child" from the "parent?
...You need to state this in terms of an actual user Scenario, ...using your actual object names...

JeffCoachman
OK...
In my form frmSQLKeyword I have four fields, SQLKeyword, Clauses, Syntax, and Purpose. The fields Clauses, Syntax and Purpose provide data to the table tblSQLKeyword in that I am using combo boxes.
Now lets say as I am entering a new record and when I come to Purpose, the Purpose I need has not been entered. I don't want to close the form and go to the Purpose table to enter a new Purpose then return to the form frmSQLKeyword in order to select the new Purpose for that will apply to that Keyword.
I hope this helps
ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for staying with me on this. Great job!
lol
Nothing that you asked for was particularly "Complicated"

I knew it was just a matter us "understanding" each other...

Glad I could help.
;-)

Jeff