need to make tables of same primary id

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to make a database of my tutors but it would contain just so much
information unique to each particular person. Thus, my tables would require
many,many colums. Can I make separate tables but which refer to the same id.
And how do I reflect this when in making forms.
 
I need to make a database of my tutors but it would contain just so much
information unique to each particular person. Thus, my tables would require
many,many colums. Can I make separate tables but which refer to the same id.
And how do I reflect this when in making forms.

You can create tables in a "one to one" relationship - just use the
same type of field as the Primary Key of each. You'ld establish a
relationship by joining the Primary Key of the main table to the
Primary Key of the second table. There is still a directionality, a
"master" table and one or more dependent tables. Typically you'ld use
a Form for the master table and one or more Subforms for the related
tables.

HOWEVER!

It is *almost certain* that if you need more than thirty fields or so,
that you have some embedded one-to-many relationships. Are you certain
that you don't have some repeating fields among these "so much
information"? Just for example, if you have a series of InteviewDates,
then you don't want many interview date fields - you want another
table. Could you describe the nature of this information? I've done a
lot of "people tables" and have never needed anywhere even close to
Access' 255 field limit.

John W. Vinson[MVP]
 
Thanks. At least now i can make the one-to-one relationships.

Two things bugging me are
1. data on say a tutor's past grades
2. the different estates the tutor is willing to go to

For No. 1, is it a one-to-many relationship that I have to use or still a
one-to-one relationship since the data is unique to the individual tutor
For No.2, say i have 30 different estates and want the form(subform?) to
include yes/no checkboxes, would I put each estate as a field in the tutor's
table or use a diferent table.
 
hoirul said:
Thanks. At least now i can make the one-to-one relationships.

Two things bugging me are
1. data on say a tutor's past grades
2. the different estates the tutor is willing to go to

For No. 1, is it a one-to-many relationship that I have to use or still a
one-to-one relationship since the data is unique to the individual tutor
For No.2, say i have 30 different estates and want the form(subform?) to
include yes/no checkboxes, would I put each estate as a field in the tutor's
table or use a diferent table.

If One Tutor gives many grades, this is one-to-many. Grades would go in a
different table (which will have a foreign key tied to the primary key --
maybe "TutorID" in the Main Tutor Table). Otherwise, for every grade the
tutor gave, you would have to have a separate field in the Tutor Table. I
imagine this Grades table might also have a StudentID to indicate who is
getting the grade (and probably there is then a Student Table with a primary
key of StudentID for each student, and information about them), and also
possibly a Courses Offered Table with a primary key of CourseID, which might
also reflect as a foreign key in the Grades tables. Each of these tables
has their own unique primary key, which is used as a foreign key in other
tables to make the relationship.

It is also one-to-many relationship if one tutor visits more than one
estate -- (One Tutor, Many Estates). To test my logic in designing
tables, I often ask myself questions like "Is this estate unique to one
Tutor, AND is this tutor unique to one Estate?" A great help to me in
organizing tables was a poster who pointed out something like the following
"Do Estates have Tutors or do Tutors have Assignments to Estates?" This
would depend on the main purpose of your db -- to track Estates that have
many different qualities (including Tutors), or to track Tutors who have
many different activities (including visiting estates).

This is more complicated if you have several tutors that visit each estate.
In this case, you may need to structure your tables differently.

I manage a db for a non-profit that offers many different classes (mostly in
one place, but sometimes elsewhere). The tables are structured something
like the following -- this is simplified format for example (PK indicates
primary key, FK foreign key)

tblClass tblStudents tblCourse tblStudentRecord
ClassID(PK) StudentID(PK) CourseID AttendanceID(PK)
CourseID(FK) StName CoName ClassID (FK)
Date StAddress Teacher StudentID(FK)
Location StDetails Length

Please note that in my case, I have only one teacher teaching each specific
event, and only one event of a course on any given day.

If I had many teachers teaching the same course in different locations, I
might need a Teachers table and a Locations Table as well. Using this
structure, I can enter information about each event of the class in
tblClass, include the CourseID in that record, thus linking to all the
details in the tblCourse, without storing all this information in the
tblClass -- I only store the CourseID.

On my main Form for entering events of classes, I have a subform
(continuous) that is tied to the tblStudentRecord, so that I can enter who
attended. This subform uses both the ClassID of that event, and the
StudentID from the tblStudent. Now my tblStudentRecord does not store all
the Student info (name, address, etc) -- only their StudentID (a number). I
can use queries, forms, and reports to pull up Student info and details of
their attendance record for viewing.

I am a "newbie", but following the advice of many on this newsgroup, have
found that taking a good hard look at what information I need, and how it is
used, is critical to setting things up "right". (ps. the tbl examples
above are truncated and over-simplified from my db -- but if any MVPs see
flaws in my logic and think I may be pointing Hoirul in the wrong direction,
please point it out!)

Hope that is helpful,
Carol
 
Thanks. At least now i can make the one-to-one relationships.

Two things bugging me are
1. data on say a tutor's past grades
2. the different estates the tutor is willing to go to

For No. 1, is it a one-to-many relationship that I have to use or still a
one-to-one relationship since the data is unique to the individual tutor

No. It is a one to many relationship. One Tutor has many Grades; you
need a second table with TutorID and Grade. Each record in this table
refers uniquely to a single tutor; but a given tutor might have
several records in the table.
For No.2, say i have 30 different estates and want the form(subform?) to
include yes/no checkboxes, would I put each estate as a field in the tutor's
table or use a diferent table.

This is a many to many relationship. You will need THREE tables:
Tutors (with TutorID as the primary key); Estates, a thirty-row table
(which can be edited, with new estates added or old ones changed or
deleted); and TutorEstates, with one row for each estate which a tutor
will visit. A continuous Subform with a combo box allowing the user to
select an estate (for each row) is convenient here.

John W. Vinson[MVP]
 
John Vinson said:
No. It is a one to many relationship. One Tutor has many Grades; you
need a second table with TutorID and Grade. Each record in this table
refers uniquely to a single tutor; but a given tutor might have
several records in the table.


This is a many to many relationship. You will need THREE tables:
Tutors (with TutorID as the primary key); Estates, a thirty-row table
(which can be edited, with new estates added or old ones changed or
deleted); and TutorEstates, with one row for each estate which a tutor
will visit. A continuous Subform with a combo box allowing the user to
select an estate (for each row) is convenient here.

John W. Vinson[MVP]
OK, I need to provide the whole list of estates in the subform so that it
would be easy to just selest or deselect the estates each tutor is willing to
go to.
Would it be right if I just obtained the list of estates from the Estate
table, put into a list box? And from there choose the multiple select
property as "simple". But how would I link/display the selected estates back
to the another TutorEstates table reflecting which tutor picked which estates?
Or do I have the wrong idea about going?
 
OK, I need to provide the whole list of estates in the subform so that it
would be easy to just selest or deselect the estates each tutor is willing to
go to.
Would it be right if I just obtained the list of estates from the Estate
table, put into a list box? And from there choose the multiple select
property as "simple". But how would I link/display the selected estates back
to the another TutorEstates table reflecting which tutor picked which estates?
Or do I have the wrong idea about going?

I'd suggest instead a continuous subform with a Combo Box on each row,
allowing an estate to be selected from the list on each line.

If you want to use a multiselect listbox, you can - it involves some
moderately involved VBA code. If you want to tackle it, here's an
example that I've used in one of my applications (an animal shelter
database in which it's necessary to record health issues for each
animal):

Private Sub cmdProcess_Click()
' Comments : Update the AnimalCondition table based on the
' selections in
' the unbound multiselect listbox lstHealthIssues.
' Newly selected rows will be added to the table,
' newly cleared
' rows will be deleted.
' Parameters: None
' Modified : 01/29/02 by JWV
'
' --------------------------------------------------
' Populate the AnimalCondition table with the selected issues
On Error GoTo PROC_ERR

Dim iItem As Integer
Dim lngCondition As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset

' save the current record if it's not saved
If Me.Dirty = True Then
Me.Dirty = False
End If
Set db = CurrentDb
' Open a Recordset based on the table
Set rs = db.OpenRecordset("AnimalCondition", dbOpenDynaset)
With Me!lstHealthIssues
' Loop through all rows in the Listbox
For iItem = 0 To .ListCount - 1
lngCondition = .Column(0, iItem)
' Determine whether this combination is currently
' in the table
rs.FindFirst "[AnimalID] = " & Me.AnimalID & " AND " _
& "[HealthIssueID] = " & lngCondition
If rs.NoMatch Then ' this item has not been added
If .Selected(iItem) Then
' add it
rs.AddNew
rs!AnimalID = Me.AnimalID
rs!HealthIssueID = lngCondition
rs.Update
End If ' if it wasn't selected, ignore it
Else
If Not .Selected(iItem) Then
' delete this record if it's been deselected
rs.Delete
End If ' if it was selected, leave it alone
End If
Next iItem
End With
rs.Close
Set rs = Nothing
Set db = Nothing
Me.subAnimalCondition.Requery

PROC_EXIT:
Exit Sub

PROC_ERR:
MsgBox "Error " & Err.Number & " in cmdProcess_Click:" _
& vbCrLf & Err.Description
Resume PROC_EXIT

End Sub



John W. Vinson[MVP]
 
Back
Top