让我解释一下
奇怪的
客户要求,我们正在抓狂:
我们有一个MS Access VBA应用程序,在数百个表单中有数千个表单字段。
这些表单中的几个字段填充来自几个表/查询的数据。
表单中的一些其他字段通过查询/直接代码将数据插入到一些表中。
请注意,这些表是
链接表
到SQL Server表。
因此,我们需要一些工具/宏来实现这一点。
如何在MS Access中找到哪些表单字段指向哪些数据库字段?
基于
@ClintB's answer
ctl.ControlSource
Sub GetFormFieldToDBFieldMapping()
Dim frm As Object
Dim LiveForm As Form
Dim ctl As control
Dim i As Integer
Dim fso As Object
Dim ctlSource As String
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile("D:\ControlSources.txt")
For Each frm In Application.CurrentProject.AllForms
'To access form controls, open it
DoCmd.OpenForm frm.Name, acViewDesign
Set LiveForm = forms(frm.Name)
For i = 0 To LiveForm.Controls.Count - 1
Set ctl = LiveForm.Controls.Item(i)
If ctl.ControlType = 106 Or ctl.ControlType = 111 Or ctl.ControlType = 110 Or ctl.ControlType = 109 Then
ctlSource = ctlSource & vbCrLf & "Form Name :" & LiveForm.Name & ": Control Name :" & ctl.Name & ": Control Source :" & ctl.ControlSource
End If
Next i
'Do not forget to close when you are done
DoCmd.Close acForm, frm.Name
Next
oFile.WriteLine ctlSource
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Sub