S
Steve Linberg
Hello everyone.
I'm kicking a lot of rust off my MS-Access knowledge after many years
away, and trying to implement something I think should be simple, and I
am hoping can be done without coding, as it would seem to be a common
need for properly normalized data.
As a simple example, I want to create a database that tracks people and
colors they like, and a form that allows this to be simply controlled.
There's a table of people, a table of colors, and a child table with
people and colors. Very generically, in other words, the tables would
basically be this:
tblPeople:
ID autonumber
txtName text
tblColors:
ID autonumber
txtColor text
tblPeopleColors:
PersonID number
ColorID number
If Joe likes blue, red and green, there are 3 records in tblPeopleColors
with Joe's ID, and the IDs for the colors blue, red and green.
What I want to do is build a form that simply controls this in Access.
It would use tblPeople as its main record source, and for each person,
it would show their name, and then all of the colors in tblColors
(probably in a listbox?), selected or not according to whether there's a
record in tblPeopleColors for that person and each color.
Selecting or unselecting colors would, when the record is closed, result
in records being created or deleted from tblPeopleColors as needed to
make tblPeopleColors reflect the state of the selected colors, one for
each record, adding or deleting as needed.
I wrote some VB to do this manually, hooking into the form's
Form_Current and Form_BeforeUpdate events to populate the selected
states of each row in the listbox and write out the differences if the
form was dirtied, but this seems awfully tedious and I have to do it
often enough that I wonder if there isn't a simpler way.
Is there a way to do this with a subform and not have to manually create
and delete records as the selections of colors are changed? The key
thing is that the list has to show all of the available colors from
tblColors, not just those that are selected, and hopefully be smart
about when to update and when it doesn't need to.
Any advice appreciated. Thanks.
I'm kicking a lot of rust off my MS-Access knowledge after many years
away, and trying to implement something I think should be simple, and I
am hoping can be done without coding, as it would seem to be a common
need for properly normalized data.
As a simple example, I want to create a database that tracks people and
colors they like, and a form that allows this to be simply controlled.
There's a table of people, a table of colors, and a child table with
people and colors. Very generically, in other words, the tables would
basically be this:
tblPeople:
ID autonumber
txtName text
tblColors:
ID autonumber
txtColor text
tblPeopleColors:
PersonID number
ColorID number
If Joe likes blue, red and green, there are 3 records in tblPeopleColors
with Joe's ID, and the IDs for the colors blue, red and green.
What I want to do is build a form that simply controls this in Access.
It would use tblPeople as its main record source, and for each person,
it would show their name, and then all of the colors in tblColors
(probably in a listbox?), selected or not according to whether there's a
record in tblPeopleColors for that person and each color.
Selecting or unselecting colors would, when the record is closed, result
in records being created or deleted from tblPeopleColors as needed to
make tblPeopleColors reflect the state of the selected colors, one for
each record, adding or deleting as needed.
I wrote some VB to do this manually, hooking into the form's
Form_Current and Form_BeforeUpdate events to populate the selected
states of each row in the listbox and write out the differences if the
form was dirtied, but this seems awfully tedious and I have to do it
often enough that I wonder if there isn't a simpler way.
Is there a way to do this with a subform and not have to manually create
and delete records as the selections of colors are changed? The key
thing is that the list has to show all of the available colors from
tblColors, not just those that are selected, and hopefully be smart
about when to update and when it doesn't need to.
Any advice appreciated. Thanks.