inheritance

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

Guest

I was wondering if it possible to do inheritance within Access 2003, as i
have 3 tables that mostly use the same fields but i would like to create a
'super-table' and 'sub-table' so the sub-table would inherit the fields...

Regards
 
I must be missing something. What would be the purpose of a "sub table",
when you can create a query to show only the fields you want?
 
well it's not the case of making a query

basically what is it I'm creating a system that will hold details of
monitors, base units, laptop and printer... which of all will have a serial
number, make and model but after the difference will be that they will hold
different details out it's self like printer type, spec of the pc/laptop and
size of the monitor.

so the idea was that I would create a super-table called Item which would
hold common details like serial number, make and model then would be linked
to the 3 different tables Base unit/Printers and monitor which would inherit
the common fields from the 'item' table

Thanks for help
 
BV2312 said:
I was wondering if it possible to do inheritance within Access 2003, as i
have 3 tables that mostly use the same fields but i would like to create a
'super-table' and 'sub-table' so the sub-table would inherit the fields...

Regards
 
Bhav said:
well it's not the case of making a query

basically what is it I'm creating a system that will hold details of
monitors, base units, laptop and printer... which of all will have a
serial number, make and model but after the difference will be that
they will hold different details out it's self like printer type,
spec of the pc/laptop and size of the monitor.

so the idea was that I would create a super-table called Item which
would hold common details like serial number, make and model then
would be linked to the 3 different tables Base unit/Printers and
monitor which would inherit the common fields from the 'item' table

Thanks for help

I believe you want a parent table and child table. The exact
relationships and construction of the tables would depend on many factors
that are likely unique to your application.
 
It sounds like you want related tables. If you open the Samplpe database
Northwind.mdb and click on the relationships icon you will see that the
Orders table is related to the Customers table. The orders table has a
CustomerID foreign key to the Customers table.

That relationship links each order to a specific customer.

There are some Access tutorials that you might find helpful at:
http://office.microsoft.com/en-us/training/CR061829401033.aspx
 
Nah it's not related tables, have you done Object Orientated design before?
it's like that, i know access it more RDMS than OO but i heard it was
possible...

Again cheers
 
Ah! I see.

I kind of understand inheritance, but not enough to be of help to you here.
The suggestions I might make probably would be off-base as to what you want.

What we need here is a C++ programmer who knows Access too.
 
object oriented?

OOP is obsolete; it's time to use DATABASES; kids

-Aaron
 
what you're looking for is called a CROSSTAB query

it will take values in a table and render them horizontally

-Tom
 
Thanks. I took a crash course in C++. Everything made sense until the
instructor tried to teach us Inheritance and polymorphism in the last week.

You can create classes in VBA. A good souce on that is the Access 2000
Developer's Handbook Vol I.
 
Some of the high end RDBMS providers have attempted to provide something
like OOP into their systems, but it's really only something that sort of
resembles OOP, it doesn't have all it's features. Typically this is done
through a TABLE datatype, which Access does not support.
 
Hi Bhav

What you are talking about here is usually called "subclassing", not
"inheritance" in the context of database design - I think that's where the
confusion has crept in.

You can create your "Item" table with a primary key (an autonumber "ItemID"
might be safer than using serial number) and another byte numeric field
named "ItemType". Then add another unique index comprising ItemID *and*
ItemType.

Create another table named "ItemTypes" with PK "ItemType" (byte numeric) and
a text field "ItemTypeName". Populate this with:
1 Base Unit
2 Printer
3 Monitor
...etc

Now, for each type of item, create another table with a two-field primary
key: ItemID/ItemType, and whatever other item-specific fields you require.
For example, for BaseUnits you have:
ItemID (long numeric)
ItemType (byte numeric, default value:1 validation rule: =1)
CPUType
RAM
...etc

Note that for each of these tables, the ItemType defaults to (and can only
be) the corresponding type code from the ItemTypes table.

Next, create relationships:
ItemTypes.ItemType > Items.ItemType (one-many)

and for each of the subclass tables:
Items.ItemID/ItemType > Subtable.ItemID/ItemType (one-one)
(this relationship can have cascading deletes if you wish)

Now, you cannot add a record to one of the subtables unless a record
matching both ItemID *and* ItemType exists in the Items table. Furthermore,
you cannot change the ItemType in the Items table if a corresponding record
exists in a subtable.

For data entry, create a main form based on the Items table and a subform
based on each of the subtables. Add one of the subforms (the largest) to
your main form, and set the properties of the subform control as follows:
Name: sbfSubClass
SourceObject: <blank>
LinkMasterFields/LinkChildFields: ItemID;ItemType
(these should have been set automatically)
For the ItemType control on the main form, use a combo box with its
RowSource set to the ItemTypes table.

Now some code... add the following to your form module:

Dim aTables As Variant
Dim aSubforms As Variant

Private Sub Form_Load()
aTables = Array("", "BaseUnits", "Printers", "Monitors")
aSubforms = Array("", "sbfBaseUnits", "sbfPrinters", "Monitors")
End Sub

Private Function LoadSubform()
Dim sSubForm As String
sSubForm = aSubforms(Nz(ItemType, 0))
With sbfSubClass
If .SourceObject <> sSubForm Then
.SourceObject = sSubForm
End If
End With
End Function

Private Sub ItemType_BeforeUpdate(Cancel As Integer)
Dim sTable As String, sMsg As String
sTable = aTables(Nz(ItemType.OldValue, 0))
If Len(sTable) <> 0 Then
If DCount("*", sTable, "ItemID=" & ItemID) <> 0 Then
sMsg = "There is data in the " & sTable & " table for this item." _
& vbCrLf & "If you change this item to a " & ItemType.Text _
& " then this " & sTable & " record must first be deleted." _
& vbCrLf & "Do you wish to continue?"
If MsgBox(sMsg, vbYesNo Or vbExclamation _
Or vbQuestion Or vbDefaultButton2) = vbYes Then
CurrentDb.Execute "Delete * from " & sTable _
& " where ItemID=" & ItemID
Else
Cancel = True
ItemType.Undo
End If
End If
End If
End Sub

Insert your own table names and subform names in the Array statements. Note
that these names could all be stored in tables if you prefer.

Set both the form's OnCurrent property and the ItemType combo box's
AfterUpdate property to:
=LoadSubform()

Hope this gives you enough to get going. Please post back and report how
you got on :-)
 
Hi Graham, Brendan, Lynn Bill and Punjab_Tom

Just want to say thanks to all of you for your help..

I haven't started to make my system but I wanted to know if it was possible,
my system should be created by end of next week and I will post back with my
results!! To be honest I need to normalize it first properly (i have always
gone straight to 3rd normal never been able to do steps) once done then my
system can be created!

Again thanks to all

Regards!!

Graham Mandeno said:
Hi Bhav

What you are talking about here is usually called "subclassing", not
"inheritance" in the context of database design - I think that's where the
confusion has crept in.

You can create your "Item" table with a primary key (an autonumber
"ItemID" might be safer than using serial number) and another byte numeric
field named "ItemType". Then add another unique index comprising ItemID
*and* ItemType.

Create another table named "ItemTypes" with PK "ItemType" (byte numeric)
and a text field "ItemTypeName". Populate this with:
1 Base Unit
2 Printer
3 Monitor
...etc

Now, for each type of item, create another table with a two-field primary
key: ItemID/ItemType, and whatever other item-specific fields you require.
For example, for BaseUnits you have:
ItemID (long numeric)
ItemType (byte numeric, default value:1 validation rule: =1)
CPUType
RAM
...etc

Note that for each of these tables, the ItemType defaults to (and can only
be) the corresponding type code from the ItemTypes table.

Next, create relationships:
ItemTypes.ItemType > Items.ItemType (one-many)

and for each of the subclass tables:
Items.ItemID/ItemType > Subtable.ItemID/ItemType (one-one)
(this relationship can have cascading deletes if you wish)

Now, you cannot add a record to one of the subtables unless a record
matching both ItemID *and* ItemType exists in the Items table.
Furthermore, you cannot change the ItemType in the Items table if a
corresponding record exists in a subtable.

For data entry, create a main form based on the Items table and a subform
based on each of the subtables. Add one of the subforms (the largest) to
your main form, and set the properties of the subform control as follows:
Name: sbfSubClass
SourceObject: <blank>
LinkMasterFields/LinkChildFields: ItemID;ItemType
(these should have been set automatically)
For the ItemType control on the main form, use a combo box with its
RowSource set to the ItemTypes table.

Now some code... add the following to your form module:

Dim aTables As Variant
Dim aSubforms As Variant

Private Sub Form_Load()
aTables = Array("", "BaseUnits", "Printers", "Monitors")
aSubforms = Array("", "sbfBaseUnits", "sbfPrinters", "Monitors")
End Sub

Private Function LoadSubform()
Dim sSubForm As String
sSubForm = aSubforms(Nz(ItemType, 0))
With sbfSubClass
If .SourceObject <> sSubForm Then
.SourceObject = sSubForm
End If
End With
End Function

Private Sub ItemType_BeforeUpdate(Cancel As Integer)
Dim sTable As String, sMsg As String
sTable = aTables(Nz(ItemType.OldValue, 0))
If Len(sTable) <> 0 Then
If DCount("*", sTable, "ItemID=" & ItemID) <> 0 Then
sMsg = "There is data in the " & sTable & " table for this item." _
& vbCrLf & "If you change this item to a " & ItemType.Text _
& " then this " & sTable & " record must first be deleted." _
& vbCrLf & "Do you wish to continue?"
If MsgBox(sMsg, vbYesNo Or vbExclamation _
Or vbQuestion Or vbDefaultButton2) = vbYes Then
CurrentDb.Execute "Delete * from " & sTable _
& " where ItemID=" & ItemID
Else
Cancel = True
ItemType.Undo
End If
End If
End If
End Sub

Insert your own table names and subform names in the Array statements.
Note that these names could all be stored in tables if you prefer.

Set both the form's OnCurrent property and the ItemType combo box's
AfterUpdate property to:
=LoadSubform()

Hope this gives you enough to get going. Please post back and report how
you got on :-)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Bhav said:
well it's not the case of making a query

basically what is it I'm creating a system that will hold details of
monitors, base units, laptop and printer... which of all will have a
serial number, make and model but after the difference will be that they
will hold different details out it's self like printer type, spec of the
pc/laptop and size of the monitor.

so the idea was that I would create a super-table called Item which would
hold common details like serial number, make and model then would be
linked to the 3 different tables Base unit/Printers and monitor which
would inherit the common fields from the 'item' table

Thanks for help
 
BV2312 said:
Nah it's not related tables, have you done Object
Orientated design before? it's like that, i know
access it more RDMS than OO but i heard it was
possible...

Access, like classic VB, supports Classes, in its VBA code (but not
inheritance, even there). And its "partial support of OO" does not extend
to database tables.

To accomplish what you describe, you'd use a parent table, a child table,
and obtain the combination of information you describe with a Query that
joins the two tables and extracts the information.

Larry Linson
Microsoft Access MVP
 
Bitch Ass Whore;

Microsoft Access _DOES_ support the 'Table DataType'

it is called Access Data Project

lose the training wheels you worthless MDB script kiddie

Tom
Punjab, India
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top