comments inline.
Thank you so much for this. It almost works for me now.
you're welcome; let's see if we can give it that last nudge...
One complication: One book can have several authors, so I set up a
junction
table. Here are my tables:
Books
BookID Primary Key
Title
<other info about the book as an object>
People
PersonID Primary Key <autonumber>
Name
<other identifying information>
Authorship
ID Primary Key <autonumber>
BookID <related to BookID in Books>
PersonID <related to PersonID in People>
excellent! i'm impressed that you correctly identified the relationship as
many-to-many between Authors and Books, and correctly set up a junction
(or
linking) table to model the relationship as two one-to-many relationships
between the parent tables (People and Books) and the child table
(Authorship). that's very, very good.
one note: if you posted the literal names of your tables and fields,
recommend that you don't use "Name" in the People table. first, Name is a
reserved word in Access and so should not be used to name anything that
*you* name in Access (clearer than mud, i hope!). second, standard
practice
is to NOT store a complete name in one field, because that does not
conform
to normalization rules; rather, use two or three fields such as FirstName,
MiddleName (or MI), LastName. you can concatenate these values into a
single, complete name at any time in a query, form, or report, as needed.
I have set up a form "Books" (based on the table "Books") and a
subform
"Authors subform" (based on a junction table "Authorship").
again, correct - well done.
I used code by Dev Ashish on the site you referred me to to add new
records
to the People table when I am working in the Books form.
ah, you've discovered the excellent advice and examples to be found at
www.mvps.org/access. bookmark that puppy!
That part works great. The new Author names appear in the People
table.
BUT, when I go back to that same Book in the Books form, no authors
appear!
It seems I have lost the connection between the Book and the Author.
Here are some relevant values from the properties of the combo box in the
Authors subform:
Control Source BookID
ok, this is incorrect. the ControlSource property of the combo box should
be
PersonID - you're choosing an author in this combo box droplist, not a
book.
RowSource SELECT [PersonID], [Name] FROM [People];
RowSourceType Table/Query
BoundColumn 1
ColumnCount 2
ColumnWidths 0";1.5"
Limit To List yes
the rest of the properties look correct (remember that when you fix the
"Name" fieldname in the People table, you'll need to change the fieldname
in
the combob box RowSource too, or you'll get an error). fix the first
property as noted above, and try again. if you're still having a problem,
post the code you're using in the combo box's NotInList event
procedure,
and
we'll see if there's something there to be modified.
hth
Thanks again for any help.
you need to be clear about the relationship between the Authors
table
and
the Books table first, and then design your forms accordingly. from
your
description, it sounds like there is a one-to-many relationship between
Authors and Books; that is, on Author may have many books, but each
Book
is
written by only one author. if this is a correct description of the
"real
world" relationship, then the relationship should be expressed in
Access
as
Authors.AuthorID 1:n Books.AuthorID
or to put it in relational terms:
ParentTable.PrimaryKeyField 1:n ChildTable.ForeignKeyField
In my "Books" table, each record is a book, and in each record
there
is
a
field for "Authors." I have a related table for "Authors" that
includes
a
list of all authors and their contact details.
your above description sounds correct for the one-to-many relationship
that
i outlined.
Craig is correct in advising you to use forms for data entry rather
than
tables. let me add to that: if you have a Lookup field in your
Books
table
(or any other table), recommend that you get rid of the Lookup. for
more
information, see
http://home.att.net/~california.db/tips.html#aTip8.
okay, now that we've laid out the table design, let's look at forms. a
mainform/linked subform setup is as follows: main form is bound to the
*parent* table, and subform is bound to the *child* table. your
setup
is
backward, with the child table Books bound to the main form, and the
parent
table Authors bound to the subform. you cannot force a mainform/subform
link
to work that way. if you want to enter "Books" data in a form, and have
the
ability to add data about a new author when the book's author is not in
the
Authors table, then you need a different setup.
i recommend that you create a single form, bound to the Books table.
use
a
combo box control (with the *RowSource* property set to the Authors
table),
to provide a list of all authors so you can assign an author to each
new
book record. when the book's author is not listed in the combo box
droplist,
you can use the combo box control's NotInList event to run code that
opens
another form which is bound to the Authors table, add the new author
record,
update the droplist with the new record, and assign that author to the
control.
the above is a standard solution to your data entry issue. if you need
help
implementing it, post back and i'll walk you through it.
hth
Thank you. I'm sure this is putting me on the right track. But I still
can't
figure out how to make my "Authors" table update when I enter data
into
the
"Books" form.
The main form is "Books" and the subform is "Author subform." The
"Author"
field in the "Books" form is linked to the "Authorname" field in
the
subform. The subform is dependent on the Authorname field in the
larger
"Authors" table. When I add a new name to the subform, the
"Authors"
table
adds a new record. Good! But the "Books" table is unaffected.
When I add the name to the Author field in the "Books" table the
"Authors"
table is unaffected.
Surely I shouldn't have to enter the author data twice every time I
enter
a
book that has a new author.
What am I doing wrong?
T
in
message Use a form and subform.
The form containing data about the books (or authors) and the
subform
containg data about the authors (or books).
Working with tables directly may seem quick and easy like a
spreadsheet,
but in the end it will be very limiting.
This assumes you have a relation (normalised table) for Books and
one
for
Authors.
--
Slainte
Craig Alexander Morrison
Crawbridge Data (Scotland) Limited
Small Business Solutions Provider
What I need to do should be the simplest thing in the world, but I
have
scoured the training pages, the help files, faqs, technical
articles
and
sample databases, and have found nothing. It may be that I am just
using
the "wrong" terminology.
I am review editor for an academic journal. My Access database
keeps
track of books received, and people willing to review these books.
My
job
is to get a reviewer together with a book.
In my "Books" table, each record is a book, and in each record
there
is
a
field for "Authors." I have a related table for "Authors" that
includes
a
list of all authors and their contact details.
What I want to do is this:
When a book arrives, I want to enter its information INCLUDING
AUTHOR(S)
in the "Books" table. I enter the Author information in a ComboBox
that
looks at the Author's table for a list of possible values. I
have
the
"Limit to List" property on this Combo box set to "No." But when I
enter
a new Author, the Author table is not updated. The new author is
only
listed with the current book.
There must be some way to add a new "Author" record to my
Authors
table
whenever I enter a new Author to a record in the Books table.
There is probably some simple answer to this question. Thanks
for
any
help.
T
When I enter a new Author