473,410 Members | 1,904 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,410 software developers and data experts.

Populating a Table from two other tables

Hi There

I am creating a questionaire to find out how a participant will grade particular subjects.

I have a list of 20 subjects in a table called Subjects.

I have created a form in which the participant enters their details and these are stored in a Customer table.

I then want to populate a table Customer_Subjects with fields Customer and Subject so that there is a record in the new table for the customer and every subject. ie

John Physics
John Maths
John English

How would I do this?

Also, ideally I would like to be able to do this automatically when the save record button is pressed on my original new customer form. What is the best way for this?

Many Thanks
Oct 6 '18 #1
9 1878
PhilOfWalton
1,430 Expert 1GB
Welcome to Bytes, Terence

Your question is rather vague. You have the information before you, we can only guess what you want

See https://bytes.com/faq.php?faq=how_to...fic_guidelines

Anyway, I'm going to assume that you have done things correctly and have 2 tables
Expand|Select|Wrap|Line Numbers
  1. TblCustomers
  2.     CustomerID         AutoNumber     Primary Key
  3.     CustomerFirstName  Text
  4.     CistomerLastName   Text
  5.     ....
  6.     ....
and
Expand|Select|Wrap|Line Numbers
  1. TblSubjects
  2.     SubjectID   AutoNumber    Primary Key
  3.     Subject     Text Required - Yes, Allow Zero Length - No 
  4.                      Indexed - Yes(No Duplicates)
Then you need a new table to join the 2 tables above
Expand|Select|Wrap|Line Numbers
  1. TblJoinCustomerSubject
  2.     CustomerID   Number Long Joint Primary Key
  3.     SubjectID    Number Long Joint Primary Key
  4.     Grade        Number
  5.  
Set up and enforce relationships between the 3 tables.

Your main for will be for customers and you will have a continuous Subform with Combo Boxes for the various subjects

Here is a botched picture to give you the idea.



The beauty of this method is that although you normally would have the Customer as the main form, and see the subjects he studies on the subform, you can do it the other way round, and have the Subject as the main form and see which customers are studying that subject.

Phil
Attached Images
File Type: png Form&ContinuusSubform.png (21.2 KB, 367 views)
Oct 7 '18 #2
Thanks Phil... appologies for the vagueness. Will try to improve that next time.

Yes I had setup the table correctly. The outcome I am trying to get is a little different from what you suggested though.

To use your example, say I have the following table
TblSubjects
SubjectID Subject
1 Maths
2 Physics
3 Biology
4 English

If then I create a new customer record in the following table
TblCustomers
CustomerID CustomerFirstName CustomerLastName
1 John Smith

How can I then autopopulate TblJoinCustomerSubject with records so that the new customer has a record for each subject (see below)?

CustomerID SubjectID
1 1
1 2
1 3
1 4


Terence
Oct 7 '18 #3
PhilOfWalton
1,430 Expert 1GB
The tables are fine, and the Join table will give you exactly what you have, but you also said you needed a column of Grades as well, and you may also need a column to show the Date the Grade was awarded. They also go into the Join table as mentioned in an earlier post.

In regards to the "Populate" your table automatically.
Now here are some question that need careful thought before answering.

1) Will EVERY Customer ALWAYS be involved with ALL 20 subjects?

2) What happens when you add Subject 21? (I ask this because a database should be designed to be "future proof" - e.g. additional or change of subjects.

3) If the answer to question 1 is "Yes" (and I would be a little surprised if it were), is your intention to add the 20 Subjects automatically as you enter a new Customer?

What you are asking for is comparatively simple to achieve, but you will need to use a bit of VBA code. Are you happy with this?

Phil
Oct 7 '18 #4
Hi Phil

In regard to your questions:
1. Yes
2. If subject 21 is added, existing customers will still have 20 subjects, however future customers will have 21 subjects populated for them.
3. Yes... All subjects to be automatically populated when adding a new customer.

VBA will be fine. I will learn as I go.

Thanks.
Oct 7 '18 #5
PhilOfWalton
1,430 Expert 1GB
Hi Terence

OK, I suggest you have a go at creating your Customer Main form and a continuous Subject Subform. Remember, with the Subform, the RecordSource should include all the fields from your Join table + Subject from your TblSubjects. Also it needs setting to Allow Edits - No, Allow Additions - No and Allow Deletions - No.

If you would like me to look at this before dealing with the automatic population of the Join table, let me know.

Phil
Oct 8 '18 #6
Okay. Thanks will make sure that It is set up the way you suggest. No need for me to run it by you at the moment.

Would love if you can let me know how to automatically populate using VBA though.
Oct 8 '18 #7
PhilOfWalton
1,430 Expert 1GB
First things First

Phil
Oct 8 '18 #8
"First thing first"?

I appreciatte your help Phil but I am not wanting you to look at the tables and form set up. My tables and forms are different to those described here. I have used your example tables for simplicity.

If you answer the question according to the setup you described, I can then adjust it to my setup.

Will you do this or not?
Oct 8 '18 #9
zmbd
5,501 Expert Mod 4TB
(...) To use your example, say I have the following table
TblSubjects
SubjectID Subject

If then I create a new customer record in the following table
TblCustomers
CustomerID CustomerFirstName CustomerLastName
1 John Smith

How can I then autopopulate TblJoinCustomerSubject with records so that the new customer has a record for each subject (see below)?

CustomerID SubjectID
1 1
(...)
Not sure where Phil is going with this at this point; however, I'm sure that he's waiting for you to let us know that your forms are properly setup.

While we're waiting, I would think that a simple update/append query should achieve this action.

Start with a simple select query - this is based on a student database I use - you should be able to get the idea.

For a single student we would start with something like"
Expand|Select|Wrap|Line Numbers
  1. SELECT StudentList.PK_StudentList
  2.  , t_Assignment.PK_Assignment
  3. FROM StudentList, t_Assignment
  4. WHERE (((StudentList.PK_StudentList)=1));
This should give you the Cartesian product between the two tables filtered down to one student.

Make sure the query looks right (one record entry for each combination of the student and subject) then one would switch to the action query - here I'll use t_ActiveAssignments:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO t_ActiveAssignments 
  2.   ( FK_StudentList, FK_Assignment )
  3. SELECT StudentList.PK_StudentList
  4.  , t_Assignment.PK_Assignment
  5. FROM StudentList, t_Assignment
  6. WHERE (((StudentList.PK_StudentList)=1));
You can use this as a stored query and have the VBA code set a member of the TempVars Object (Access) collection for the criteria:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO t_ActiveAssignments 
  2.   ( FK_StudentList, FK_Assignment )
  3. SELECT StudentList.PK_StudentList
  4.  , t_Assignment.PK_Assignment
  5. FROM StudentList, t_Assignment
  6. WHERE (((StudentList.PK_StudentList)
  7.    =TempVars![StudentID]));
This way one doesn't have to open a recordset etc...
Oct 12 '18 #10

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

Similar topics

1
by: Ward B | last post by:
Greetings. I'm somewhat new to this whole MySQL/PHP thing and need a little help. My web hosting service uses phpMyAdmin and at the bottom of the screen iis an area where I can upload a text...
1
by: Svelte Poshy | last post by:
Populating a field in a table depending on another In my table customers i want to populate the field segmenid depending on the choice in the lookup field Typeid. Both fields, typeid and...
1
by: shobhit_shanker | last post by:
Here are the relevant "givens" to my problem... Form: frmLaunchRpt - Text Box: txtAsOfDate - Check Box: chkLogEval - Command Button: cmdLaunchRpt Report: rptEvaluation - Text Box:...
0
by: dino07 | last post by:
Hi All, I am currently trying to do the following: 1. insert a value into a repeating table from a drop-down list( secondary storage) when the user click the "Add" button positioned next to the...
3
by: gg77 | last post by:
Hi, I don't have much knowledge of the table control. I am basically trying to use a table thats populated with data rows from a dataSet but currently things aren't working for me. below is...
1
by: keliie | last post by:
I have a relatively simple (I assume) issue which I am at a complete loss to address. My issues is: I want to populate fields in my tables with summary data from the same table. Let me explain: ...
3
by: Richard Rosser | last post by:
Greetings. Can somebody please point me in the direction of good reference material with a 'how-to' on building a web form that will post selected data from the form to an Access (2002) as well...
14
anfetienne
by: anfetienne | last post by:
hi this question is linked to this post ive made in the mysql section. http://bytes.com/topic/mysql/answers/871536-populating-table#post3499253 simply i want to use a form to populate a table...
2
by: calbaptedm | last post by:
Have a table with my master information for individuals and would like to automatically export the data to other tables based on the criteria selected. On my master table you can select multiple...
2
by: lgoddgreat | last post by:
Hi I have this project, and I've been working on it for days. I decided to add something like a tracking record on my project, the users Login and Logout time will be tracked and stored on the ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.