有时我们需要获取整个项目中所有窗体中的组合框和列表框的行来源,可以使用以下代码实现:
Dim fm As AccessObject
Dim ctl As Control
Me.txtNotes = ""
For Each fm In CurrentProject.AllForms '遍历所有窗体
If fm.Name <> Me.Name Then
Debug.Print fm.Name
DoCmd.OpenForm fm.Name, acDesign
For Each ctl In Forms(fm.Name).Form.Controls '遍历窗体控件
If ctl.ControlType = 111 Then '如果窗体上有控件111组合框或110列表框
Me.txtNotes = Me.txtNotes & fm.Name & " " & ctl.Name & "组合框 行来源:" & ctl.RowSource & vbCrLf '取组合框和列表框的行来源
End If
If ctl.ControlType = 110 Then '如果窗体上有控件111组合框或110列表框
Me.txtNotes = Me.txtNotes & fm.Name & " " & ctl.Name & "列表框 行来源:" & ctl.RowSource & vbCrLf '取组合框和列表框的行来源
End If
Next
DoCmd.Close acForm, fm.Name, acSaveYes
End If
Next
MsgBox "完成"
示 例:
点击下载此附件
演 示: