MS ACCESS:使用另一个表中的数据填充子表单
我的 Access 数据库中有三个表。
**Table: Participants**
ParticipantID
FirstName
LastName
Address
Phone
SiteNameLookup
YearLookup
**Table: DailyWorkshops**
WkshpID
WkshpDate
AorB
SiteStaff
Artists
Activities
**Table: ParticipantAttendance**
ParticipantID Participants.ParticipantID
FirstName Participants.FirstName
LastName Participants.LastName
WkshpID DailyWorkshops.WkshpID
Level *(here I have a lookup to fill in HALF/PARTIAL/FULL, not just yes/no)*
我已成功创建了一个表单 DailyWorkshopsForm,它具有 ParticipantAttendance 子表单。该子表单完全是空白的。
现在,我如何从参与者表单中填充 ParticipantAttendance 子表单,以便我所要做的就是检查每个参与者的出勤级别?我可以弄清楚如何仅查找 Participant.ParticipantID 或仅 Participant.FirstName 或仅 Participant.LastName --- 但查找一个不会自动填充其他...所以我最终可能会查找 ID #但没有得到与之相配的名字。
编辑:问题和问题的澄清问题。
谢谢...当我仔细研究它时,我意识到 ParticipantAttendance 不是子表单应该的样子...这只是出勤数据最终应该存在的表。我需要的子表单是这样的:
WkshpID ParticipantID FirstName Lastname Level
6 10-45 Bart Simpson Full
6 10-47 Ned Flanders Half
6 10-49 George Washington None
6 10-50 Michelle Obama Full
7 10-45 Bart Simpson Full
7 10-47 Ned Flanders Full
7 10-49 George Washington Half
7 10-50 Michelle Obama None
8 10-45 Bart Simpson Full
8 10-47 Ned Flanders None
8 10-49 George Washington Half
8 10-50 Michelle Obama Half`
I have three tables in my Access Database.
**Table: Participants**
ParticipantID
FirstName
LastName
Address
Phone
SiteNameLookup
YearLookup
**Table: DailyWorkshops**
WkshpID
WkshpDate
AorB
SiteStaff
Artists
Activities
**Table: ParticipantAttendance**
ParticipantID Participants.ParticipantID
FirstName Participants.FirstName
LastName Participants.LastName
WkshpID DailyWorkshops.WkshpID
Level *(here I have a lookup to fill in HALF/PARTIAL/FULL, not just yes/no)*
I have succesfully created a form, DailyWorkshopsForm, that has a subform of ParticipantAttendance. This subform is completely blank.
How can I now populate the ParticipantAttendance subform from the Participants form so all I have to do is check off the attendance level for each participant? I can figure out how to look up just Participant.ParticipantID or just Participant.FirstName or just Participant.LastName --- but looking up one doesn't automatically fill in the others... so I could end up looking up an ID # but not get the name that goes with it.
Edit: Clarification of question & problem.
Thanks... as I look at it more I realize ParticipantAttendance is not what the subform should be... that's just the table where the attendance data should ultimately live. What I need for the subform is something that looks like this:
WkshpID ParticipantID FirstName Lastname Level
6 10-45 Bart Simpson Full
6 10-47 Ned Flanders Half
6 10-49 George Washington None
6 10-50 Michelle Obama Full
7 10-45 Bart Simpson Full
7 10-47 Ned Flanders Full
7 10-49 George Washington Half
7 10-50 Michelle Obama None
8 10-45 Bart Simpson Full
8 10-47 Ned Flanders None
8 10-49 George Washington Half
8 10-50 Michelle Obama Half`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看子表单的属性,您会发现有一种方法可以指示父表单和子表单之间的“外键”关系(查看“数据”、“链接主字段”到“链接”)子字段”)。在您的情况下,您需要链接两个表的 WkshpID 字段。
然后只需在子表单中使用普通的 SQL 查询
SELECT * FROM ParticipantAttendance
,WHERE 条件将由 MS Access 使用父表单中的外键关系自动强加,并在您导航时及时更新到父表单中的其他数据行。If you look to the properties of the subform, you'll see that there is a way to indicate a "foreign key" relation between the parent form and the subform (look at the "Data", "Link Master Fields" to "Link Child Fields"). In your case you need to link the field WkshpID of both tables.
Then just use a normal SQL query as
SELECT * FROM ParticipantAttendance
in your subform, the WHERE condition will be automatically imposed by MS Access using the foreign key relation from the parent form and duly updated as long as you navigate to other data row in your parent form.