Very Basic Relationship Question

Pingo

Registered User.
Local time
Today, 16:24
Joined
Oct 10, 2008
Messages
16
I'm not new to Access, but I've been away from this for a long time (too long it seems).

I'm trying to create a clients database that holds info about Corporate clients and Consumer clients.

I've got tblClients which hold a primary key of ClientID (AutoNumber) and ClientType (1 for corporate, 2 for consumer).

I've got 2 more tables which holds the actual information: tblClientsCorp, tblClientConsu.

What is the way I need to connect the tables so when I open a new client i will get the new ClientID right on the start?
 
You will need a form that is bound to your tblClients and then a SubForm that links to your MainForm via the ClientID, and is bound to your tblClientsCorp. The subform wizard should look after this for you.

Given that you have two tables tblClientsCorp, tblClientConsu, you will need two SubForms on your MainForm.

You will then need to test ClientType, in the "On Load" event and the "On Current" event and also after the ClientType has been set or changed to determine which of the SubForms you wish your user to see.
 
John thanks for the reply. You've actually solved me my next question :)

But actually I'm more in the level of defining the relationships. So I have ClientID in the tblClients and it's a primary key.

Should the primary key in both the other tables should be with the same name and linked with a relationship?

What I've meant is that if I want to create a new record, I want that the record will be created in the tblClients and also in the other tables? is this possible without too much code?

I hope that I've explained myself well enough, but I'm just looking to define the tables at this point.
 
So I have ClientID in the tblClients and it's a primary key.

Yes

Should the primary key in both the other tables should be with the same name and linked with a relationship?

Yes, but it won't be a primary key it will be a foreign key. That's not to say that those records may not have their own primary keys.

What I've meant is that if I want to create a new record, I want that the record will be created in the tblClients and also in the other tables? is this possible without too much code?

That's what the Form/SubForm set up I described earlier will do.
 
John,

If I create a query that combines all of the information before loading the form, I can use it as my record source and doens't need all of the sub forms?

which is the better practice?
 
I you want to see all the sub records for one mater record at the same time you will need a SubForm set up.
 
Sorry, I just had a bit more of a think about my previous answer as you are using a query to populate your form, then you could just use a continuous form.
 
Is there a good reason why you need different tables for consumers and corporate clients?
 
@neileg:

I'm saving different information for the corp clients and the private ones. Actually the system I'm working on is intended for a company that runs after school activities in schools and in private events.
The corp clients are schools which I need to save info like contact persons, name of the school, and other specific info such as school code, website, attachments field for some school specific documents and so on.

For private customers I need to save only name and address. that's all. In the future I want the possibility of adding other types of customers without redesigning the database.

by the way, beside the different client tables, I'm tracking all the other info the same tables, such as planned activities and so forth.

@john:
Newbie question: if I have the 2 tables connected as you've said, and I create a new record on the tblClientsCorp, and it's primary key is connected to tblClients- Can't Access create a new record with the autonumber in the tblClients table?
 
I understand what you say. But that suggests to me that there is no logical reason for using the same run of ID numbers for both types.
 
I can't quite follow you. Why would I have two sets of numbers for clients? it can only confuse the users. furthermore If I will have more than 2 types of clients, then I would have to rewrite many queries, instead of just running every query with the tblClients at first.
 
Pingo, here is a different take on your question regarding why you have the same run of numbers for consumers and corporate clients.

There are pot-loads of normalization rules and some of them can be stated technically to such a complex level as to obscure the meaning of the rule. So..., here is the MEANING of the rule about keys.

Normalization is about filtering and isolating the contents of a table such that every item you see in the table depends EXACTLY AND ONLY on the prime key. That allows the key to be a stand-in for the entire record by proxy (and by lookup or join, in practical terms). That is the "real" meaning of having a relationship between two tables.

The problem here is defining which is the "one" side and which is the "many" side. The design you have shown us is somehow reversed. Since the only thing in your parent table (as you described it) is a number and a class-code (consumer/corporate), I wonder why you even need this information?

Let's take a look at what I mean by that. In the tblConsumer and tblCorporate stuff, you have the key number as a foreign key. But will this information be a one-to-many case? It superficially looks like it would be one-to-one as the way you described it. In that case, all you would use that PK number for is to look up the class code. But since you knew already (based on which table it was in) that this was a consumer or corporate client, you have everything you need already in the individual tables.

So the question then becomes, WHY did you want to co-mingle these values?

Here is my thought, and perhaps this will open your eyes to a different viewpoint. Your data set seems like the parts have almost totally independent origins. Is there a need for a unique number from either table to be honored by the other table? (This is a question YOU must answer, based on your knowledge of the program.)

How often do those tables get treated separately? How often must they come together? If they are mostly separate but you have one or two reports or VERY simple queries that work on the lowest common subset of fields that exist in both of the original tables, consider a UNION query as a way to merge the tables when they need to be merged. Otherwise, let them be independent.

If I have missed your intent here, sorry. It was not my desire to confuse you. However, your problem description does not clarify the need for joining these apparently disparate data subsets. Which is why Neil and I seem skeptical.
 
Hi Doc_man,

first of all thanks for the lengthy explanation. I've forgotten how much is the access developers community is around the world.

I clearly see your point. But what if I want a unique ID for every client that will follow the same logic? how can add this into the database if I've got 2 independent tables?

I've planned to use the AutoNumber as the ClientID.
 
Last edited:
Another idea:

what if i use one table only for all the clients. They're basically the same. only difference is that on corporate clients I need to save the company name and a second contact information.
 
Another idea:

what if i use one table only for all the clients. They're basically the same. only difference is that on corporate clients I need to save the company name and a second contact information.
When I suggested this you ruled it out!
 
@neilg:

it took me some time to understand it at first, sorry for that. but isn't this not exactly normalizing? if I have 50% corporate clients and 50% private, isn't it a lot of "space" in the table for nothing?
 
I know what you mean, but empty space isn't used. I'm not an expert programmer, just war hardened. I tend to do whatever makes life easy.
 
I know what you mean, but empty space isn't used. I'm not an expert programmer, just war hardened. I tend to do whatever makes life easy.


completely with you on that one.
 

Users who are viewing this thread

Back
Top Bottom