Access Newbie asks for help.

T

tallentd

I am new to Access and have created a database for my company. I have a
situation that I know can be done but I am just not sure as to how to do it.
My business is a church planting organization and I have created a database
of churches and church planters (the one who starts the church). There is
only one planter to a church but a church can have multiple pastors. I would
like Access to populate the current pastor fields in the current pastor table
with the planter data from the planter table if the checkbox that I have
created in the current pastor table is set to true which means that the
planter is
the current pastor.
Hopefully this makes sense. Any help would be greatly appreciated.
 
K

Ken Sheridan

One piece if information you haven't provided is whether a pastor can
minister to multiple churches, or only one church. This makes a difference
to the model as in the former case the relationship between churches and
pastors is many-to-many rather then one-to-many.

Ken Sheridan
Stafford, England
 
T

tallentd

Ken,
Thanks for your response.
A church can have only one planter.
A planter can have multiple churches.
A church has multiple pastors.
I have my relationships set up and everything is working well. What I need
to know and I probably needed to be more clear. For the purpose of extracting
the data via query or report I need the database to look to the Current
Pastors table to see if the checkbox is checked confirming that the original
planter is the current pastor. If that box is checked then the database
should pull the info on the planter rather than coming up with empty fields.
If at all possible I would like the database to populate the fields of the
current pastor with planter data if that box is checked in forms for data
entry purposes. What I am trying to avoid is to having duplicate data.
Hopefully that makes better sense.
 
K

Ken Sheridan

You haven't explicitly answered my question as to whether a pastor can
minister to multiple churches. I ask this because here in the UK its quite
common for a clergyman in the Church of England to be the priest for a number
of churches, particularly in rural areas where a group of parishes, which in
the past would each have had their own parish priest are now covered by a
single priest. Moreover, group ministries are also common, where a group of
churches are covered by a group of priests, so each priest has more than one
church, and each church has more than one priest, i.e. the relationship type
is many-to-many.

In your case the relationship type between churches and planters is clearly
many-to-one.

You have already said "a church can have multiple pastors", but not
explicitly whether the reverse is also the case. For the moment I'll assume
you are saying 'no' by omission, and each pastor ministers to one church
only. But as you'll see it requires only a small amendment to the model to
cater for the alternative scenario.

Pastors and planters are really a single entity type which can be related to
Churches in one or both of two different ways, planter and/or pastor. I'll
simply call it Pastors for the moment. As each entity type is represented by
a table you would have a Pastors table. Columns in tables represent the
attribute types of the entity type, e.g. PastorID, FirstName, LastName, etc.

Churches are another entity type of course, so you'd have Churches table
with columns as appropriate to represent the attribute types of churches. As
the relationship between churches and planters is clearly many-to-one, and
each church will have one planter, no more no less, then you simply need to
PlanterID column as a foreign key referencing the PastorID primary key of
Pastors.

As far as the relationship of pastors to churches is concerned you could
simply have a ChurchID column in Pastors, again as a foreign key referencing
the PastorID primary key of Pastors. However, I'd recommend modelling the
relationship in a different way, by a ChurchPastors table. This would have
two foreign key columns PatorID and ChurchID referencing the primary keys of
Pastors and Churches respectively. This means that as well as holding
information about the church's current pastor you could store information
about pastors over time by including DateFrom and DateTo columns in this
table. The current pastors are those where the DateTo column is Null. Even
if you are only recording the current pastors, representing the relationship
by a table does avoid having Null foreign keys in Churches.

If a pastor can only minister to one church at a time, then you would create
a unique index on the PastorID and DateFrom columns jointly, If you are only
storing the current pastors, and omitting the date columns then index the
PastorID column uniquely.

If a pastor can minister to more than one church simultaneously don't create
the unique index on the PastorID and DateFrom columns (or just PastorID), but
index the PastorID column non-uniquely (duplicates allowed). In either case
index the ChurchID column non-uniquely.

The above represents a robust model I think, with no redundancies, though
these things always need thorough testing. Where the planter is also the
current pastor the relevant PastorID value would be entered in the PlanterID
column in Churches (via a combo box bound to PlanterID but showing the
person's name) and there would be a row in ChurchPastors with the relevant
ChurchID and PastorID values (also entered via combo boxes showing pastor and
church names) and a Null DateTo column if you do opt to store 'historic' data
about incumbencies.

There is no need for the check box because everything is inherent in the
data itself, and by joining the tables appropriately in queries it can be
correctly returned. Note that if you are returning both planter and pastor
data in a query you should include two instances of the pastors table in a
query, not join twice to a single instance. If you do this in query design
view Access will automatically give the second instance an alias to
distinguish them.

For data entry purposes a Churches form, based on the churches table, and a
Pastors subform based on the ChurchPastors table would be an appropriate
one-stop-shop solution.

Ken Sheridan
Stafford, England
 
T

tallentd

Ken,
My apologies for not being clear.
A church planter can "plant" multiple churches.
A church planter can go and pastor another church that someone else has
started.
A pastor can "plant" multiple churches.
A church exists only once in our database and can only have one planter but
we are only tracking the planter and the current pastor of each church.
So at any given time we only have one church, one planter and one current
pastor. For our historical purposes we need not document how many pastors a
church has had. Only the planter and who is currently pastoring. That was my
reasoning for the checkbox.
I have a church table, a planter table and a current pastor table. By having
each in their own table I can keep historical data. The amount of fields in
each table is great. We are keeping full data on the church, the planter and
the current pastor. Hire date, coaches and mentors, spouse, children,
birthdays and anniversaries for the planter. Not quite as much on the current
pastor and complete data on each church (Baptisms, Attendance and Offering,
Small Groups). We are also keeping the historical data. I was told by a guy
from New Horizons, that in our case we should have a separate table for each
of these and just use a relationship to tie them together. Is that not
correct? I have alot of tables. Coaches, Mentors, Regions, Staff that
interacts with each entity individually, CPN's (Church Planting Networks)
that have members from various churches and are connected only to the
churches, not the pastors or planters.
If the planter is the current pastor then I would like the query or report
to pull the planter info in to the current pastor info. If I cannot
accomplish this by the means of a checkbox please let me know that my
thinking is incorrect. I am guessing that it has to do with a macro or access
language that I have no clue about.

I think I just need to go to a class as I would probably need to show
someone what I have put together and have them help. There are so many
variables to what we do.
I do appreciate your help though. It would probably be easier for you to
help me if I could explain myself better.
 
C

Clif McIrvin

Another perspective on the discussion so far follows:

tallentd said:
Ken,
My apologies for not being clear.
A church planter can "plant" multiple churches.
A church planter can go and pastor another church that someone else
has
started.
A pastor can "plant" multiple churches.
A church exists only once in our database and can only have one
planter but
we are only tracking the planter and the current pastor of each
church.
So at any given time we only have one church, one planter and one
current
pastor. For our historical purposes we need not document how many
pastors a
church has had. Only the planter and who is currently pastoring. That
was my
reasoning for the checkbox.

1. So every time a pastor changes the old data needs to be replaced by
new data - and - if the pastor moves to another of the churches in your
database his data needs to be re-entered for the new church. Not at all
a good use of the capabilities of access.

2. Now you have need of information re: only the planter and current
pastor. Can you guarantee that there will never be a time in the future
when you become interested in additional historical data? Ken's 'term of
incumbancy' suggestion adds a trivial amount of data to your dabase.
(and greatly simplifies the process of changing current pastor.)
I have a church table, a planter table and a current pastor table. By
having
each in their own table I can keep historical data. The amount of
fields in
each table is great. We are keeping full data on the church, the
planter and
the current pastor. Hire date, coaches and mentors, spouse, children,
birthdays and anniversaries for the planter.

Here's a good entry for a discussion on normalization: as I understand
your table structure you have made provision (great number of fields) to
store much data, and I'm inclined to think that frequently many of these
fields will be empty because the data does not apply to this pastor or
church.

For only one example, you mention children. If you remove child fields
from the pastors table and create a related (sorry - the standard term
here is parent / child relationship when disucssing related tables in a
databse) and create a related children table in a many-to-one
relationship with the pastors table you can easily have anywhere from
zero to ??? children for each pastor.

Not quite as much on the current
pastor and complete data on each church (Baptisms, Attendance and
Offering,
Small Groups). We are also keeping the historical data.

You just lost me: keeping the historical data? But only have data on
the plater and current pastor? I'm missing something here. Again, if I
understand you correctly, Ken's Pastor/Church table with incumbency data
solves both current staff and historical data issues.

I was told by a guy
from New Horizons, that in our case we should have a separate table
for each
of these and just use a relationship to tie them together. Is that not
correct? I have alot of tables. Coaches, Mentors, Regions, Staff that
interacts with each entity individually, CPN's (Church Planting
Networks)
that have members from various churches and are connected only to the
churches, not the pastors or planters.
If the planter is the current pastor then I would like the query or
report
to pull the planter info in to the current pastor info. If I cannot
accomplish this by the means of a checkbox please let me know that my
thinking is incorrect. I am guessing that it has to do with a macro or
access
language that I have no clue about.

I think I just need to go to a class as I would probably need to show
someone what I have put together and have them help. There are so many
variables to what we do.
I do appreciate your help though. It would probably be easier for you
to
help me if I could explain myself better.

Did you happen to see the message thread " i dont know how to use this
program" ?

Look up John Vinson's reply to that thread -- his reply is complete with
a set of links to resources where you can dothis class on your own.


Good Luck!

--Clif
 
T

tallentd

So instead of changing the current pastor I should keep the historical of
currrent pastors associated by dates? Would I then build the query to choose
only from the active pastor of a church?
 
C

Clif McIrvin

tallentd said:
So instead of changing the current pastor I should keep the historical
of
currrent pastors associated by dates? Would I then build the query to
choose
only from the active pastor of a church?

Yes .. your test for current pastor is based on the DateTo field. Set
the criteria in the Query Design Grid for DateTo to IsNull.

Remember that the DateFrom and DateTo fields are in the ChurchPastor
table that Ken suggested, not in either the Churches nor Pastors table.

This gives you a 'permanent' historical record (at least until you
decide to delete historical data.)

The link that associates a pastor to a church is the many-to-many
"junction table" (ChurchPastor): ChurchID and PastorID are both foreign
keys in the ChurchPastor table which is related many-to-one to both the
Churches and Pastors Tables. This way (enforce referencial integrity)
Access takes care of 'connecting' which pastor(s) are associated with
which church(es).
 
K

Ken Sheridan

No need to apologise; you were clear in everything you said, just didn't
quite say everything. I had assumed from this that the situation is as
you've now clarified it, but the model I suggested gave the opportunity, with
minimal amendment, to cater for both scenarios, as Clif has pointed out. Of
course, even if you design the database so hat you can record previous as
well as current pastors, it doesn't mean you have to record the previous
ones; you can still record only the current ones if you prefer. The option
to record previous ones will still be there should you decide in future to do
so.

When it comes to what tables you need we need to consider the theoretical
basis of the database relational model to some degree. A reasonable grasp
of the underlying principles does make it a lot easier designing the 'logical
model' i.e. the tables and the relationships between them which go to make up
the database. Getting the logical model correct at the start is the key to a
robust and efficient database as it is a model of the underlying part of the
real world which the database represents. If the logical model doesn't
accurately reflect the underlying reality, then developing a smoothly
functioning application is going to give a lot of headaches, if it does then
developing the interface will be pretty straightforward on the whole.

Before looking at your specific situation it might help if I give you a
couple of my stock replies, firstly on the relational model. You might like
to print this off so you can consider it at leisure:


"The database relational model was originally proposed by E F Codd in a
paper in 1970 in the journal 'Communications of the Association for Computing
Machinery'. Since then there has been a vast amount of further theoretical
work, and the relational model has shown itself to be a robust one. Without
going too deeply into the theoretical basis, which can be quite abstract, a
relational database in essence models a part of the real world in terms of
its entity types and the relationship types between them. Note the inclusion
of the word 'type' in both cases here. While its almost always used in the
former case, its often omitted in the latter case. This is a little bit
sloppy but not too important. When one talks about a 'relationship' it
really refers to a relationship value. As an example 'marriage' is a
relationship type, but my being married to my wife Fiona is a relationship
value, represented by our names on the marriage certificate, which is the
physical equivalent of a row in a Marriages table with columns Husband and
Wife, each referencing the primary key of a table People. This is a
many-to-many relationship type (I've been married twice so would be in two
rows, my first wife would also be in two rows as she remarried too). It is
resolved into two one-to-many relationship types, People to Marriages in each
case, in one case via the Husband column in the other via the Wife column.

In a relational database tables model Entity Types. In the above example
People is an entity type, modelled by the People table. Marriage is also an
entity type, modelled by the Marriages table. As we've seen its also a
relationship type. In fact a relationship type is just a special kind of
entity type.

Each column in a table represents an attribute type of each entity type, so
attribute types of People might be FirstName, LastName, DateOfBirth etc.
This table would also have a PersonID numeric column (usually an autonumber)
as its primary key as names are not unique. Each row in a table represents
one instance of the entity type, and the attributes of each instance are
represented by values at column positions in the row. This is the only way
that data can be legitimately stored in a relational database.

Its important that there is no redundancy in the information content of the
database. This is achieved by the process of 'normalization'. Normalization
is based on a set of 'normal form's ranging from First Normal Form (1NF) to
Fifth Normal Form (5NF). There is also one called Boyce/Codd Normal Form
(BCNF) which was inserted when it was found that the original Third Normal
Form was deficient; it didn't cater satisfactorily for tables with two or
more candidate keys where thee keys were composite and overlapped, i.e. had a
column in common. I won't go into the details of normalization here; you'll
find it written up in plenty of places.

To see an example of redundancy and therefore a table which is not properly
normalized take a look at the Customers table in the sample Northwind
database which comes with Access. You'll see that it includes City, Region
and Country columns. If you look at its data you'll se that we are
redundantly told that São Paulo is in province SP which is in country Brazil
4 times. This is not just inefficient, it is dangerous as it leaves the
table open to inconsistent data being entered. There is nothing to stop
somebody putting São Paulo in the UK, USA or in each in separate rows in the
table for instance. To normalize the table it should be decomposed into
Customers, Cities, Regions and Countries tables, each of the first three with
a foreign key referencing the primary key of the next table up in the
hierarchy."


and secondly on normalization (this does duplicate some of the above):


"Normalization is the process of eliminating redundancy from a database, and
involves decomposing a table into several related tables. In a relational
database each table represents an entity type, e.g. Contacts, Companies,
Cities, States etc. and each column in a table represents an attribute type
of the entity type, e.g. ContactID, FirstName and LastName might be attribute
types of Contacts and hence columns of a Contacts table. Its important that
each attribute type must be specific to the entity type, so that each 'fact'
is stored once only. In the jargon its said that the attribute type is
'functionally dependent' solely on the whole of the primary key of a table.

To relate tables a 'referencing' table will have a foreign key column which
makes the link to the 'referenced' table, e.g. a Contacts table might have a
CompanyID column as a foreign key, while a Companies table has a CompanyID
column as its primary key. Consequently no data other than the CompanyID
needs to be stored in a row in the Contacts table for all the company
information for that contact to be known; its available via the relationship
and can be returned in a query joining the two tables on the CompanyID
columns.

Similarly the Companies table might have a CityID column and the Cities
table a StateID column. If its an international database the States (or more
generically Regions) table would have a CountryID referencing the primary key
of a Countries table. So via the relationships, simply by entering (in
reality this would be selected from a list of Companies in a combo box, not
typed in)a CompanyID in the Contacts table the location of the contact's
company is also known. Redundancy, and therefore repetitive data entry is
avoided.

To see how a database is made up of related tables take a look at the sample
Northwind database. Its not completely normalized in fact (deliberately so
for the sake of simplicity) but illustrates the main principles of how tables
representing entity types relate to each other. An example of its lack of
proper normalization can be found in its Customers table. You'll see that
this has City, Region and Country columns so we are told numerous times that
São Paulo is in SP region (as is Resende) and that SP region is in Brazil.
Not only does this require repetitive data entry, but more importantly it
opens up the risk of 'update anomalies', e.g. it would be perfectly possible
to put São Paulo in California in one row and California in Ireland! Proper
normalization as I described above would prevent this as the fact that São
Paulo is in SP region would be stored only once in the database as would the
fact that SP region is in Brazil and California is in the USA.

An example of what at first sight might seem to be redundancy, but in fact
is not, can also be found in Northwind. The Products table and the
OrderDetails table both have UnitPrice columns. It might be thought that the
unit price of a product could always be looked up from the Products table, so
its unnecessary in Order Details. However, the unit price of a product will
change over time, but each order needs to retain the price in force at the
time the order was created. Consequently a UnitPrice column is needed in
both tables; that in products holds the current price and is used to get the
value for that in Order Details (code in the ProductID control's AfterUpdate
event procedure in the Order Details Subform does this), which then remains
static when the current price (in products) changes. In each case UnitPrice
is functionally dependent on the key of the table, so there is no redundancy"


OK, if you've managed to plough through that and stay awake, lets consider
your scenario in the context of these underlying principles. I can't really
say to what degree the advice you've been given on the need for specific
tables is sound or not. I'd need to know a lot more details of the
underlying 'reality' which the database needs to model. But keep in you mind
that each table represents an entity type and each column represents an
attribute type of the entity type in question. Each attribute type must be
specific to the entity type (this is where normalization comes in as
described above). In the jargon its said that each non-key column must be
'functionally dependent' on the whole of the primary key of the table, or as
John Vinson once said 'The key, the whole key and nothing but the key, so
help me Codd', which is a nice way of remembering what makes a table
normalized to Third Normal Form (3NF).

So, Churches is obviously an entity type and things like the name and
location of the church are its attribute types, as is it planter, the last
represented by a PlanterID foreign key column.

When it comes to people connected to the church in some way or other things
get a little more complex, but not frighteningly so, as the principles
involved are quite simple. All people share certain attribute types of
course; we all have names, an address, a date of birth and so on. So there
is an entity type People with these common attribute types, and a table can
represent this attribute type. People with different roles may well have
attribute types which are specific to their role, e.g. a pastor is likely to
have attribute types which a member of his congregation would not have. If I
can use an example from the C of E an attribute type for a C of E priest
might be Date of Ordination. So the entity type Pastors is a sub-type of the
entity type People. The way a sub-type is modelled in a relational data base
is by means of a one-to-one relationship. In the case of People and its
sub-type Pastors this would mean that there would be a table people with a
numeric primary key PersonID (don't use names as a primary key, they can be
duplicated), and a Pastors table also with a numeric primary key PersonID
(you can call it PastorID if you wish, but I prefer to keep the column names
the same). In the case of the Pastors table PersonID would also be a foreign
key referencing the primary key of People. The people table would have
columns for the common attributes like names and address etc., the Pastors
table would have columns only for those attribute type specific to the
Pastors entity type, e.g. Date of Ordination, but not the common attributes
like names and address.

A sub-type can of course have sub-types of its own; Chris Date in one of his
books gives the example of a type Employees with sub-type programmers, and
sub-types of programmers, System programmers and Application programmers.

As far as the primary keys are concerned, if you use an autonumber column
you can only do so for the topmost type, e.g. you could have an autonumber
PersonID column in the People table, but the primary key of Pastors or other
sub-type of people must be a straightforward long integer number data type,
not an autonumber.

When it comes to events connected with a church you need to think carefully
about how these fit into the model. One thing you need to be careful of is
deciding whether an event type is a sub-type of another type, or whether the
type of an event is an attribute type of a single entity type. You might
have a topmost Events entity type with attribute type such as Event Date,
Location etc and a Baptisms sub-type with attribute types such as ChildID,
FatherID, MotherID, all three referencing the People table. Another way of
modelling it would be to have a single Events table with an attribute type
EventType, in which a value 'Baptism' would be entered. The problem with the
latter approach of course is that if you also have ChildID, FatherID,
MotherID columns these won't be appropriate to other types of events in the
same table. In this case therefore a type/sub-type model is probably the
most appropriate. In the case of other entity types, however, the second
approach might be more suitable. To take an extreme example, in a personnel
database you would not have an Employees table and a separate table for every
Job Title in the organization; you'd be more likely to have a Positions table
and an EmployeeHistory table with EmployeeID, PositionID, DateFrom and DateTo
columns to model the many-to-many relationship between Employees and
positions.

By all means attend a class, but I'm also a greet believer in the value of
the printed word, so here's another of my stock replies, this time on Access
books:


"Of the general purpose primers on Access I particularly like John L
Viescas's 'Running Microsoft Access' (Microsoft Press).

For an introduction to VBA programming in Access Evan Callahan's 'Microsoft
Access/Visual Basic Step by Step' (Microsoft Press) is easy to follow and,
while not taking things to a very high level, provides a solid basis on which
to build.

At a more advanced level the 'Access Developer's Handbook' by Paul
Litwin,Ken Getz and Mike Gunderloy (Sybex) covers the subject in great
detail, and contains a vast amount of usable code.

A useful and easy to read little book on the theoretical basis of the
database relational model is Mark Whitehorn and Bill Marklyn's 'Inside
Relational Databases With Examples in Access' (Springer).

For a highly authoritative but quite abstract explanation of the relational
model Chris Date's 'An Introduction to Database Systems' (Addison Wesley) has
for many years been regarded as a definitive work on the subject. Its by no
means an easy read, however.

For SQL Joe Celko's 'SQL for Smarties' (Morgan Kaufmann) is a wealth of
information on how to write queries. It deals with standard SQL, however,
and is not Access oriented. In fact Joe's views on Access do not bear
repetition where they might be read by people of a sensitive disposition.
Even so it is worth its weight in gold."

Ken Sheridan
Stafford, England
 
C

Clif McIrvin

Before looking at your specific situation it might help if I give you
a
couple of my stock replies, firstly on the relational model. You
might like
to print this off so you can consider it at leisure:

Wow, Ken, good stuff. The longer I play here the more I learn :)
 

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