Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relationship problem, query data with undesired results, please help!!

Status
Not open for further replies.

dean20

Technical User
Mar 27, 2000
6
US
First of all, Thanks DougP and Elizabeth for your help!<br><br>I have another question.<br>&nbsp;I have studentID in student table 1:n grade table<br>&nbsp;I have assignmentID in Assignment table 1:n in grade table<br><br>I cannot get a full student listing on the subform. It only lists those students that already have studentID and AssignmentID linked in one record in the grade table.<br>How can I get a full student listing (those with and those without stored grades) on the subform when linking to the master form by assignmentID?<br><br>How do I get the unique records to automatically be created in the Grade Table?<br>&nbsp;&nbsp;&nbsp;EX. Student1 Assignment1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Student1 Assignment2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Student2 Assignment1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Student2 Assignment2<br>I would like these records added when an assignment is added. I hope this is a good explanation.<br><br>Thanks In advance, Dean
 
This somehow sounds familiar.<br>Right thats they way a query works.<br>It only returns the records that match both tables.<br>Is it possible to add a student to both tables and leave the grades blank<br>In other words StudentID would be added to both. <br>Then it will pull up everyone.
 
you could use a Save Button which you click and it would save the forms contents to 2 or more tables<br><br>here's some code I gave someone else awhile ago<br>----------------------------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim db As Database, rst1, rst2, rst3 As Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Set db = CurrentDb<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rst1 = db.OpenRecordset(&quot;Table1&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rst2 = db.OpenRecordset(&quot;Table2&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rst3 = db.OpenRecordset(&quot;Table3&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;rst1.AddNew<br>&nbsp;&nbsp;&nbsp;&nbsp;rst2.AddNew<br>&nbsp;&nbsp;&nbsp;&nbsp;rst3.AddNew<br>&nbsp;&nbsp;&nbsp;&nbsp;rst1![employee number] = Me![employee number]<br>&nbsp;&nbsp;&nbsp;&nbsp;rst2![employee number] = Me![employee number]<br>&nbsp;&nbsp;&nbsp;&nbsp;rst3![employee number] = Me![employee number]<br>&nbsp;&nbsp;&nbsp;&nbsp;rst1.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;rst2.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;rst3.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;db.Close<br>
 
A JOIN gives a union.<br><br>A LEFT JOIN gives all the rows on from the left table and all rows on the right table that match the condition.<br><br>A RIGHT JOIN gives all the left rows that match the condition and all the rows from the right.<br><br>Given:<br><br>&quot;Student&quot; table<br>id, int<br>name, varchar(?)<br><br>1,&quot;fred&quot;<br>2,&quot;daisy&quot;<br>3,&quot;chris&quot;<br><br>&quot;Assignment&quot; table<br>id, int<br>dsc, text<br><br>1,&quot;Write Paper&quot;<br>2,&quot;Read Book&quot;<br>3,&quot;Watch Movie&quot;<br><br>&quot;Grade&quot; table<br>Student, int (FK from Student)<br>assignment, int (FK from Assignment)<br>grade, char(2)<br><br>1,1,&quot;B&quot;<br>1,2,&quot;A-&quot;<br>2,2,&quot;B+&quot;<br><br><br>SELECT s.name, a.dsc, g.grade from grade g join student s on s.id = g.student join assignment a on a.is = g.assignment<br><br>gives graded assignments<br><br>&quot;fred&quot;,&quot;Write Paper&quot;,&quot;B&quot;<br>&quot;fred&quot;,&quot;Read Book&quot;,&quot;A-&quot;<br>&quot;daisy&quot;,&quot;Write Paper&quot;,&quot;B+&quot; <br><br><br>SELECT s.name, a.dsc, g.grade from grade g LEFT join student s on s.id = g.student join assignment a on a.is = g.assignment<br><br>gives all students, regardless of grades<br><br>&quot;fred&quot;,&quot;Write Paper&quot;,&quot;B&quot;<br>&quot;fred&quot;,&quot;Read Book&quot;,&quot;A-&quot;<br>&quot;daisy&quot;,&quot;Write Paper&quot;,&quot;B+&quot; <br>&quot;chris&quot;, Null, Null<br><br><br>SELECT s.name, a.dsc, g.grade from grade g join student s on s.id = g.student RIGHT join assignment a on a.id = g.assignment<br><br>gives all assignments regardless of grades<br><br>&quot;fred&quot;,&quot;Write Paper&quot;,&quot;B&quot;<br>&quot;fred&quot;,&quot;Read Book&quot;,&quot;A-&quot;<br>&quot;daisy&quot;,&quot;Write Paper&quot;,&quot;B+&quot; <br>Null, &quot;Watch Movie&quot;,Null<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top