NO, don't use a lookup field in your table, under any circumstances. in this
instance, it won't do a thing to help you anyway.
i think we're having a communication problem here. your initial post said
that your main form contains only a combo box control that shows a droplist
of Artists, and you want to select a specific artist and see all his/her
shows in the subform. i told you how to do that. your last post asked me to
outline a hierarchy of forms to be used for adding records. i assumed that
you meant adding records to both tables, and so i told you how to set up a
form/subform to do that; that solution does not include using a combo box
control on the main form. now you're asking about combo box control issues
again, which i assume means you're reverting to the setup you described in
your initial post.
at any rate, i've explained to you how to create both setups, so all i can
suggest at this point is that you go back and read this thread in the order
posted, and choose the solution you actually want to use. once you decide
what you want, then implement that solution *by itself* without "borrowing"
instructions from the other solution. if you have problems implementing,
post back with specific questions.
hth
Andrew L. said:
OK, I did this and the only problem I run into is this: when adding a
record, the ArtistKey field on the new (blank) record is not being
populated. I am using a combobox in the mainform displaying
ArtistName, bound to ArtistKey. The subform, based on qryShows (a
sorted Shows table), is linked to the mainform with
ArtistKey:ref_ArtistKey, as you suggested.
I don't know if that combobox is the right type of control to use, as
the dropdown works, but auto-complete does not. Should I change the
Shows table so that the ref_ArtistKey is a lookup to ArtistName in
Artists bound to ArtistKey? Years ago, one of the MVP's recommended
never using lookups in tables because he likes to see the data
actually in the table, so I haven't done that since...
the relationship your diagram displays is one to many: one artist (parent
table) may have many shows (child table), but each show belongs to
only
one
artist. if that is correct, then the standard form setup to handle a
two-table parent/child relationship is as follows:
create a form bound to the Artists table, i'll call it frmArtists. create
another form bound to the Shows table, i'll call it sfrmShows; if you want
to impose a particular order on the shows records, then build a query *that
is based on the Shows table ONLY*, and bind sfrmShows to that query. in
sfrmShows design view, either do not include a control for the ref_artistkey
field, or set the control's Visible property to No. in the design view of
frmArtists, add a subform control and name it ChildShows. set the control's
properties as follows:
SourceObject: sfrmShows
LinkChildFields: ref_artistkey
LinkMasterFields: artistkey
you can use this form/subform to add new artists, with or without shows
records, and also to edit/delete existing artist records and/or
add/edit/delete shows records for existing artist records.
hth
I'd like to get this straight here. I follow you about the subform not
being based directly on a query or table...that makes sense.
Unfortunately, I am such a rank beginner that I have no idea how to
take advantage of the error checking and validation a form can offer
for data entry. So I'll begin by making sure I follow your hierarchy
here....
--TABLES--
=Artists = =Shows=
artistkey ref_artistkey
artistname showdate
showyear
(many more...)
--Queries--
=qryShows=
ref_artistkey
artistname (from Artists)
(lots more from Shows)
Given this little strucure can you outline a hierarchy of forms to be
used for adding records. Alternately, if you can point me to sample db
with such a structure... I tried Northwind but the sample is too basic
and there is no form really designed there for data entry. I know I'm
asking pretty basic stuff here and I sure appreciate the help.
Recommendation on a really good book would be gratefully accepted,
too.
Andrew
I think this translates to: the main form is unbound but
the subform must be bound.
correct. the subform control has to be "bound" (SourceObject property
set)
to a table, query, or another form based on a table or query. otherwise
the
LinkChildFields and LinkMasterFields properties are useless, because
there
is nothing to link to.
personally, i wouldn't link a subform control directly to a table or
query.
that is basically the same thing as opening a table or query datasheet
directly for data entry and/or review - never a good idea, because you
can't
control what the user does in a table/query datasheet the way you
can
in
a
form. recommend you build a form bound to the query that's based on your
"Shows" table, then bind the subform control in the main form to that
second
form. this is the standard practice for a mainform/subform setup.
hth
I tried exactly as you wrote with no luck. The combo on main form
worked, but the subform remained empty. I tried changing the Source
Object property on subform to "Table.Shows" and then everything works
perfectly! I think this translates to: the main form is unbound but
the subform must be bound.
(As is, records were not sorted (since the source table for subform
sorts by key), so I changed the Source property for subform to a query
based on Shows, and that's even better!)
Thank you so much!
Andrew