relationship between a table as a whole and a field in another table

B

bulk88

How do I create a relationship where ALL the records in a particular
table have a relationship to 1 particular /unique record in another
table? I want a relationship between a table's name (all records in
it) and a field with the table's name in another table.

Story: I have a customer table, now each customer has 3 types of bill
templates. I made 3 tables, one for each type of bill template, with a
autonumber customer ID related back to the customer table. For 2
types of bill templates, he can only have one bill (record) for that
type of bill template; for the 3rd type of bill template table, each
customer can have infinite amount of bill templates (0-~4 in real
life). There is also a "my-business-specific info" table, with 1
record for each type of bill template. Each record in "my-business-
specific info" table is different (rec wise, not field wise), but
there are only 3 of them because there are only 3 types of bill
templates. Remote possibility more types of bill templates will be
added one day by me (the designer), not the user.

The complete bill template is supposed to be assembled by combining a
customer rec+one of the customer's bill templates recs+my business
specific rec for that type of bill template. The bill template is then
going to be printed and the items ordered and amount due written out
by hand then mailed. There is no concept of products or orders or
point in time data in this database.

I haven't finished making the application yet, I am at table design
stage. I am a first time Access user and first time anything
databases, but I have done some amateur programing in C++, Javascript,
HTML, and Perl. My VB experience is limited to 1 semester of VB
Classic years ago in high school/secondary school, but I think I can
figure VBA pretty quickly.

Another way of making this relationship I thought of is making a
"static field" in each bill template table. I thought up of a way of
making a "static field" (a textbox type) by setting the field's
default value to the table name, and then making a validation rule so
you can't change that field (I guess I can later not include a way to
see/change the "static field" from a form, but I want some protection
against myself/datasheet view too). The "static field" would have a
relationship with the "type of bill template" (listbox type I think)
field in the "my-business-specific info" table. Is there a better way
to do a "static field" than waste space on a column/field with every
rec having the same value, like a 'field source = "name of table"'?

I am trying to make a decent "normalization", if I combine the 3 types
of bill template tables together into one big bill template table,
there will be alot of empty fields for each rec, since most of the
fields on one type of bill template don't exist on any other types of
bill templates, violating normalization rules I think. But atleast I
will have a useful field with "the type of bill template" info, rather
than the "static field" solution above.

Am I asking too much of Access or relational databases, or is this
kind of relationship something usually later emulated (look up current
record set's table name, find rec in other table with same value in
field X???) by VB code in the form/report?
 
J

John W. Vinson

How do I create a relationship where ALL the records in a particular
table have a relationship to 1 particular /unique record in another
table? I want a relationship between a table's name (all records in
it) and a field with the table's name in another table.

No can do.
Story: I have a customer table, now each customer has 3 types of bill
templates. I made 3 tables, one for each type of bill template, with a
autonumber customer ID related back to the customer table.

Well... that was not a proper normalized design. Storing data (a template
type) in a tablename is *simply wrong*.

You need one templates table with one additional field - the template type.

Would that work for you, or are these tables different in *structure*? If they
are, you may need a one-to-one relationship for Subclassing.

John W. Vinson [MVP]
 
B

bulk88

On Sep 2, 10:30 pm, John W. Vinson
Would that work for you, or are these tables different in *structure*? If they
are, you may need a one-to-one relationship for Subclassing.

John W. Vinson [MVP]

75% different field/structure. I could make one table, but some fields
will be empty for one record, while another record will have a
different set of empty fields.

Can you explain "subclassing" (google says its a database term for
inheritance), and is it even possible in Access?
 
A

Armen Stein

On Sep 2, 10:30 pm, John W. Vinson


75% different field/structure. I could make one table, but some fields
will be empty for one record, while another record will have a
different set of empty fields.

Can you explain "subclassing" (google says its a database term for
inheritance), and is it even possible in Access?

A one-to-one relationship is the relational database way of
accomplishing subclassing.

That said, there is a style choice here:

1 - single table with some of the fields not applicable, and therefore
Null

or

2 - one-to-one tables for each subtype.

In your case, if 75% are common fields, then I would probably
recommend the single table. Nulls really don't cost you anything, and
handling the records is easier.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
J

John W. Vinson

Can you explain "subclassing" (google says its a database term for
inheritance), and is it even possible in Access?

Subclassing uses one to one relationships. You would have the 25% common
fields in a "master" table, and have three child tables with the same primary
key for the unique field types. It's not all that different from what you have
<g>, just with a single master table to tie things together.

For data entry you would use a form based on the master table, with three
selectable subforms for the detail data. You would need some VBA code on the
form to ensure that only one of the subforms gets edited.

John W. Vinson [MVP]
 
J

Jamie Collins

1 - single table with some of the fields not applicable, and therefore
Null

or

2 - one-to-one tables for each subtype.

In your case, if 75% are common fields, then I would probably
recommend the single table.

I'd go with the subclassing approach (2). Best to avoid nullable
columns IMO i.e. does NULL mean 'not applicable' or 'applicable but
unknown' etc?
Nulls really don't cost you anything

You obviously never lost time due to newbie thinking that NULL = NULL
evaluates to TRUE.

Jamie.

--
 

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

Top