Mar 21 2023 09:00 PM
I'm hoping it's possible to create 1:M:1 and 1:M:M forms. Simple version is I have three tables, Students, HostFamilies, and Placements. While most students stay in the same placement over the course of a year, some do move and have several families (and/or schools). The pertinent fields are:
Students
Sdt_ID | Autoincrement (primary key)
Name | Short Text
<other fields>
HostFamilies
HF_ID | Autoincrement (primary key)
HF_Name | Short Text
<other fields>
Placements
Sdt_ID | Number (long integer, primary key field 1)
Pcmnt_Num | Number (primary key field 2)
Pcmnt_type | Short text (permanent, temporary, etc.)
HF_ID | Number (long integer)
School_ID | Number (long integer)
I would like to have a form for the Students table that has both a subform for Placements (it would be tabular) that I can use to select a particular placement number, which will in turn populate a second subform from the HostFamilies table with the HF data linked through the placement in question. Ideally, it will look something like this:
Mar 22 2023 02:12 AM - edited Mar 22 2023 02:14 AM
Hi,
If you don't create a "placement" you should use a list instead of a subform.
Otherwise :
In form create an independent textbox named HF_ID. No link field !
In subform placement on current_form event use this code :
if not isnull(me.HF_ID.value) then
'copy placement number in new HF_ID textbox in form
me.parent.HF_ID.value = me.HF_ID.value
endif
In form select container of subform hostfamily, in properties LinkMasterFields and LinkChildrenFields write 2 fields of the (new) relation :
LinkMasterFields : Sdt_ID;HF_ID
LinkChildrenFields : Sdt_ID:HF_ID
If you are refresh problem on host_family subform add this before the Endif instruction.
Me.Parent.Controls("sfHostFamily").Requery
sfHostFamily is the name of CONTAINER of subform and not name of subform.
Mar 22 2023 10:02 AM
Mar 22 2023 01:23 PM
@KevvieMetal The sample database here demonstrates the use of a main form/sub form design to handle M:M relationships.
Mar 22 2023 09:24 PM
I must be doing something wrong because I can't get it to work. While I know table relationships and such from database work long ago, I'm a total noob to Access. I'm sorry I'm not catching on too well.
Mar 22 2023 09:32 PM
Thanks. I'm pretty good with basic two-table relationships (1:1, 1:M, and M:M), but I'll definitely dig into that. What I'm really bumping up against is the more complicated relationships. It doesn't help that I don't usually get the chance to work on this until after 9pm -- I'm already exhausted when I start!
Mar 23 2023 01:08 AM
Mar 23 2023 07:19 AM