【发布时间】:2019-12-11 09:54:28
【问题描述】:
我有一张如下表
BranchIds 列是一个多值列,引用了分支表的 id。 我需要如何将 id 及其相关值绑定在位于另一个访问表单中的组合框中,如下所示
权限表包含允许哪个用户访问哪个分支的数据。 我无法将 perimssion 表中的分支绑定到另一种形式的组合框。
我正在尝试的代码。经过长度搜索后从 MSDN 获得..
Sub BindBranches()
Me.comboBranchIds.RowSourceType = "Value List"
Dim db As Database
Dim rs As Recordset
Dim childRS As Recordset
Set db = CurrentDb()
' Open a Recordset for the Tasks table.
Set rs = db.OpenRecordset("SELECT BranchIds FROM Permissions WHERE UserId = " & Forms!NavigationForm!txtSession.Value)
rs.MoveFirst
Do Until rs.EOF
' Print the name of the task to the Immediate window.
'Debug.Print rs!TaskName.Value
' Open a Recordset for the multivalued field.
Set childRS = rs!BranchIds.Value
' Exit the loop if the multivalued field contains no records.
Do Until childRS.EOF
childRS.MoveFirst
' Loop through the records in the child recordset.
Do Until childRS.EOF
' Print the owner(s) of the task to the Immediate
' window.
'Debug.Print Chr(0), childRS!Value.Value
Me.comboBranchIds.AddItem Item:=childRS!Value.Value
'Me.comboBranchIds.RowSource = "SELECT BranchName FROM Branches WHERE ID = " + childRS!Value.Value
childRS.MoveNext
Loop
Loop
rs.MoveNext
Loop
End Sub
【问题讨论】: