U
UKM
I'm using Access 2003. I have three tables to model a simple
many-to-many relationship betweeen authors and titles of books (as an
example of my problem).
- Authors: has Id (autonumber, primary key) and AuthName (str, indexed, no
dups)
- Books: has Id (autonumber, primary key) and BookName (str, indexed, nop
dups)
- Book_Author: has Id, BookId and AuthId
A Titles query that maps the Book_Author id fields to their respective tables
shows me book titles and authors, just like I want.
I now want a form with two comboboxes that lets me enter new titles:
Author: -----------
Title : -----------
I'd like each combobox to show me available values or allow me to
enter a new one. My form is based on my Titles query. My Author
combobox has Authors.Name as its Control Source, and 'SELECT
Authors.Name FROM Authors;' for its Row Source.
It looks right, but doesn't work. Two problems:
1. If I enter a new author name and book name, the tables are
correctly updated, but the combobox doesn't show me the new value
when I try to add a subsequent field. Only when I close and re-open
the Form do I see this.
2. More importantly, if I select an existing name or title, I get an
error complaining that adding the field would violate an index
constraint. It makes sense to me that I'm getting this error (if I
entered an existing Author's name in my Titles query datasheet
view, I'd get the same error), but I'm not sure how I teach the
form to do what I want and use the AuthId of the author I selected
rather than try to insert a new one.
Any pointers greatly appreciated.
Thanks,
-UKM
many-to-many relationship betweeen authors and titles of books (as an
example of my problem).
- Authors: has Id (autonumber, primary key) and AuthName (str, indexed, no
dups)
- Books: has Id (autonumber, primary key) and BookName (str, indexed, nop
dups)
- Book_Author: has Id, BookId and AuthId
A Titles query that maps the Book_Author id fields to their respective tables
shows me book titles and authors, just like I want.
I now want a form with two comboboxes that lets me enter new titles:
Author: -----------
Title : -----------
I'd like each combobox to show me available values or allow me to
enter a new one. My form is based on my Titles query. My Author
combobox has Authors.Name as its Control Source, and 'SELECT
Authors.Name FROM Authors;' for its Row Source.
It looks right, but doesn't work. Two problems:
1. If I enter a new author name and book name, the tables are
correctly updated, but the combobox doesn't show me the new value
when I try to add a subsequent field. Only when I close and re-open
the Form do I see this.
2. More importantly, if I select an existing name or title, I get an
error complaining that adding the field would violate an index
constraint. It makes sense to me that I'm getting this error (if I
entered an existing Author's name in my Titles query datasheet
view, I'd get the same error), but I'm not sure how I teach the
form to do what I want and use the AuthId of the author I selected
rather than try to insert a new one.
Any pointers greatly appreciated.
Thanks,
-UKM