MS Access 2016.在表单数据表上同步两个组合框

时间:2017-12-15 23:24:37

标签: ms-access combobox cascade datasheet

我在数据表表单上有两个级联查找表组合框。(SessionCategories - SessionTypes)。我遇到了以下问题:

1)当表单加载时,我只看到SessionTypes中与第一个SessionCategories ID对应的值。

2)当我更改SessionCategories组合的值时,所有SessionTypes值都会在数据表中发生变化,而不仅仅是所选的。

有什么想法吗?我是否需要在表单加载中包含一些内容?更多信息和以下几种不同的方法。

感谢。

ATHLETE_SESSION table
sessionOverviewID
sessionTypeID

SESSION_CATEGORIES
sessionOverviewID   sessionOverview
1   aerobic
2   anaerobic 


SESSION_TYPE
sessionTypeID   sessionType sessionOverviewID
1   anaerobic1  2
2   anaerobic2  2
3   anaerobic3  2
4   aerobic1    1
5   aerobic2    1
6   aerobic3    1

sessionCategoriesID lookup properties:
Display control: Combo Box
Row Source Type: Table/Query
Row Source: SessionCategories
Bound Column: 1
Column Count: 2
Column Widths: 0cm;2cm

sessionTypeID lookup properties:
Display control: Combo Box
Row Source Type: Table/Query
Row Source:
Bound Column: 1
Column Count: 2
Column Widths: 0cm;2cm


1st approach:

Private Sub comboSessionCategories_AfterUpdate()

Dim strSQL As String
strSQL = "SELECT SessionType.sessionTypeID, SessionType.sessionType FROM SessionType WHERE (((SessionType.sessionOverviewID)=" & [Forms]![Session]![comboSessionOverview] & "))"
Me.comboSessionType.RowSource = strSQL

End Sub

2nd approach:

Private Sub comboSessionCategories_AfterUpdate()

Me.comboSessionType.RowSource = "SELECT SessionType.sessionTypeID, SessionType.sessionType" & _
" FROM SessionType WHERE SessionType.sessionOverviewID=" & Me.comboSessionOverview
Me.comboSessionType = Me.comboSessionType.ItemData(0)

End Sub

0 个答案:

没有答案