Subform help (1 Viewer)

tracey75

Registered User.
Local time
Today, 20:01
Joined
Feb 18, 2000
Messages
50
Ok, here is my situation!! I have a form with these fields: Id#, Bus Driver Name, Location, Date of Accident and then, Other Party's Name, Insurence Name, Address and so on. What i want to do is if the Bus driver had a collision with more then one party i would like to have a subform to put that information in so when i pull up the ID# the list will be at the bottom instead of having all these fields again. I have to say that i dont even know where to start If someone could please help me?? Going nuts

Thank you
 

Rich@ITTC

Registered User.
Local time
Today, 20:01
Joined
Jul 13, 2000
Messages
237
Hi Tracey75

It sounds like all your fields are within the same form and therefore probably drawn from the same table or query.

First you would need to break down your data into separate tables - Probably one for Bus Driver (with FirstName, LastName, DriverID as a minimum set of fields - more personal details could be included such as any insurance or works/department number).

Next create a second table containing data on the Other Party - again similar fields may exist, though there may be some new fields here (suggest at least OtherPartyID, FirstName, LastName, InsuranceCompany, Address1, Address2, City etc). To be honest it is normal practice to divide tables into "entity types" so even within the OtherParty table I would probably create other tables - one for addresses and one for Insurance Details.

However, let's keep to the two tables created so far - a Driver table (name it tblDriver) and an OtherParty table (name it tblOtherParty). What links these two "entities" is an unfortunate situation presumably - a crash/collision. Presumably a driver can have more than one crash (not too many/too frequently one hopes) and similarly the OtherParty could be involved in more than one incident (not common - but possible). These means we need to have a third linking table allowing us to create a "many to many" relationship.

The third, "mid-table" will need to have the primary key from the tblDriver table - DriverID, the primary key from tblOtherParty - OtherPartyID, and a unique value to identify this incident itself (IncidentID - which will be the Primary Key in this table), and probably fields for the Date, Location of crash, etc (Hint: don't call the Date - Date, this is a restricted word in Access so call it IncidentDate).

The two other IDs - DriverID and OtherID are foreign keys in this new table and must have the same format as the Primary keys in the original tables (e.g. Text or Integer).

Then in the Relationships Window link the DriverID in tblDriver with the DriverID in the new table (which you can name tblIncident). Do likewise with OtherPartID in tblOtherParty and tblIncident.

Now you have your data organised.

If you then create a form based just on the Driver - tblDriver table you will place only fields relating specifically to the driver (DriverID, FirstName etc). The Subform can be based on a Query that draws together data from tblOtherPart and tblInvoice - you can put all the fields from the two tables into this query.

Next create you subform and add (for the moment) all the fields - so the OtherPart's name, Insurance company, the location of the incident, date etc all appear. In properties (making sure you have Form selected) choose for DefaultView - Datasheet.

Save this form (as frmDriverIncidentSub). With your main form open (frmDriver)in Design view open up the Database Window at the same time (pressing F11 function key) and select the new subform and drag onto the design of the Main form. Adjust size and location of subform (so it fits in well, etc).

You now need to set something to link/associate the two forms. This is done via Child Links and Parent Links in the Property Window. Select the subform, open the Property Window and then put in a shared value between the two sources of data (tblDriver and qryIncident) - both have the DriverID value so for Child Link put in DriverID and likewise for Parent Link put in DriverID.

A bit long-winded, but that should do the trick!

[This message has been edited by Rich@ITTC (edited 07-28-2000).]
 

Users who are viewing this thread

Top Bottom