BruceM or Douglas J Steele

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Okay, I think I have everything working....almost. When I go back to my
vendor input form (I have a subform that has multi-select categories). When
I chose a category or many categories, I get a message that says "You cannot
add or change a record because a related record is required in table
'categories'.
 
In my limited experience this seems to happen when you have a relationship
set up and the data being entered on one form is not being saved to the
table before moving to another form. I would suggest checking to make sure
that the data from each form is being saved before moving to another form.
When I use a command button to move to another form I usually put a
"Refresh" command it the "Got Focus" event of the command button.

Mike
 
The meaning of "I have a subform that has multi-select categories" is not
clear. Douglas Steele has provided the basics about creating the forms and
structure needed for a many-to-many situation. How is that working out? I
only weighed in to make the point about primary keys in the junction table.
You do not create a relationship between PK fields. When you create a
relationship between a PK field and another field, the other field becomes
the foreign key because of that relationship, not because of anything you do
with the FK field in table design view. I don't know if this is a precise
definition, but it's the general idea.
What is an example of a category? If your situation is about making a list
of categories for each vendor, and if the category is a single field, you
may not need a junction table. In any case the subform needs to be based on
a table that is related to the main form's record source.
 
I removed my relationships between the vendor, junction, & categories tables.
So, now I have no relationships. I can select a category or categories
(when I am in my vendor form with a category subform), but the data does not
store anywhere.
Here's an example of my forms:
Vendor form: Bruce M 123 Main St, Anywhere, USA
Categories subform: Access Guru, Microsoft Technical Specialist, & King

I have 3 tables: Categories, junction table, vendors
1 form: Vendors
1 subform: categories
Each vendor can have more than one category and therefore each category can
have more than one vendor

I really appreciate your help. I have been working on this database on and
off for about 6 months now. My boss won't let me go to Access training, so
I'm pretty much flying by the seat of my pants.
 
Bosses can be pretty strange sometimes when they don't want to pay for
training, but are willing to pay for your time of trial and error
self-training.

I refer you to Douglas Steele's earlier reply in the other thread:
"You put Vendor information in the Vendor table. You put Category
information
in the Category table. You link vendors and categories in the junction
table.
"A common approach would be to have a form bound to Vendors, linked to a
subform bound to the junction table. The subform would have a combobox based
on the Category table bound to the Category Id in the table."

You need to have relationships for this to work. Your tables will be
constructed something like the following:

tblVendors
VendorID (autonumber PK)
Vendor name, address, etc.

tblCategories
CategoryID (autonumber PK)
Category

tblJunction
JunctionID (autonumber PK)
VendorID (data type = Number; this will be the foreign key once you have
set up the relationships)
CategoryID (same note as for VendorID)
Years_Experience

I have added Years_Experience as an example of the sort of thing that is
specific to the junction table. In this case, Years_Experience is specific
to THIS category for THIS vendor. If you need such information, you need
the junction table. You can use the junction table even if such information
is not needed.

In the Relationships window, establish a relationship between VendorID in
tblVendors and VendorID in tblJunction. Click Enforce Referential
Integrity. Do the same for CategoryID in the two tables.

Note what Douglas suggested: Make a form (frmVendors) bound to tblVendors
(i.e. tblVendors is the Record Source), and another form (frmJunction) bound
to tblJunction. frmJunction will contain a combo box bound to CategoryID.
That combo box's row source will be based on tblCategory. Use the combo box
wizard to get started. What you need to end up with is a combo box based on
a Row Source query (constructed by way of the three dots next to Row Source
in the combo box property sheet; if you used the wizard, the three dots will
let you view the query). Your row source query will contain two columns:
CategoryID in the first column, and Category in the second. The combo box
bound column will be 1, column count will be 2, column widths 0;1" (or
whatever you need for the second column).

Now, in form design view, drag the icon for frmJunction onto frmVendors.

Your problem was that you were trying to enter something into the
tblCategory, but there was no direct relationship between tblVendors and
tblCategory. If you need to add a record to tblCategory (e.g. a new
category) you will need a separate way to add the category. You could add a
command button to frmJunction to open a form based on tblCategory for those
situations when you need to edit tblCategory.

Finally, if a category name changes (e.g. Auto Mechanic becomes known as
Automotive Technician), do you want existing vendor records to reflect the
new name, or the name at the time it was added to the vendor's records?
Even if it is unlikely, what if? It could be important.

Try everything I have suggested. If it does not work, be very specific in
your reply as to what is happening. Above all, for people here to provide
useful answers, you need to be specific about what you have tried. We don't
need to know that vendor information includes city, state, phone, and all
that, but we do need to know about primary keys. When somebody suggest
something, give it a try and report back. I still don't know if your
junction table contains appropriate foreign keys, for instance.
 
Bruce -
Thanks for the help.
I did everything that you said, except I didn't quite understand that part
about dragging the icon for frmJunction onto frmVendors? I think I did it
right but, was it supposed to do something?
I also changed the category to a list box instead of a combo box.
Now when I go into my vendor form and choose a category it allows me to
highlight a category or categories, but it does not save the choices
anywhere. Don't I need to create a field where each vendor and the various
categories will be recorded?
 
Dragging the icon (from the database window, which is what you see when you
first start Access: Tables, Queries, etc.) is one way of creating a
subform. I beleive it will also work if you just open frmVendors in design
view and drag frmJunction onto it. Drag and drop, that's all, just as if
you were moving a file in My Computer. I should have mentioned that you
should set the default view of frmJunction to Continuous, so that you can
see all of the categories at once for a particular vendor. Each category
will be a new record in tblJunction. If VendorID in tblVendor is 999, and
if you use the subform to select three categories for that vendor, there
will be three records in tblJunction with 999 in the VendorID field. You
don't need to populate that field. It will happen automatically as a result
of the relationship described in the previous post.
The idea behind having each category as a separate record is that you can
have any number of categories. You don't have to guess that you will need
five Category fields, then later discover you needed six. Forget the list
box. Try the combo box as I suggested. After you have selected a category,
click the new record button at the bottom of the subform (not the main form,
but the subform) and add another category. If you want to change to a list
box later you can, but I don't think you will want to once you see how it
works.
You need to create or select a vendor record in the main form (frmVendors).
Once that is done you can add the categories.
 
OMG it works, your a genious!!
BTW, I do see what you mean about having the combo box. It will make it
much easier if a vendor decides that they no longer provide that service.
I'm sure I'll have more to ask later.
Thanks again and have a wonderful day/evening (when ever you read this?)
 
Glad to know that it worked. A couple of years ago I had to construct a
database with a many-to-many relationship, as well as needing to handle
numerous other Access situations large and small. I could not have
succeeded without the assistance of the good folks here. Now that I have
acquired some knowledge I am glad to pass some of it along.
 

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

Back
Top