Let me explain the WEIRDEST client requirement, we're scratching our heads for:
We have an MS Access VBA application with thousands of forms fields in hundreds of forms.
A few fields in these forms populates data from few tables/queries.
A few other fields in forms inserts data to few tables through queries/direct code.
Notice that these tables are linked tables to SQL Server tables.
Is there a way to find which form field is related to which table column in?
Hence, we need some tool/macro to do this.
How do we find which form field points to which database fields in MS Access?
Based on @ClintB's answer, we have prepared the following code. The values in ctl.ControlSource
doesn't seems to be referring to actual database objects:
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