Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a column name 1

Status
Not open for further replies.

nik11

Programmer
Feb 6, 2010
34
US
I want to search for a column name in the entire database. In forms, reports, etc. Purpose is to find whether this column is used for any computations. Can anyone please tell me how this can be accomplished.
 
This query should return all places forms, reports, and controls where it is used in a query
Code:
SELECT 
 Replace(Replace([Name],"~sq_c"," "),"~sq_f"," ") AS ObjectName, 
 MSysQueries.Expression
FROM 
 MSysObjects 
INNER JOIN 
 MSysQueries 
ON 
 MSysObjects.Id = MSysQueries.ObjectId
WHERE 
  (((MSysQueries.Expression) Like "*" & [Enter Field Name] & "*"))
ORDER BY 
 Replace(Replace([Name],"~sq_c"," "),"~sq_f"," ");

This code will return all forms and reports that use it:
Code:
Public Function getFieldUse(fldName As String) As String
  Dim frm As AccessObject
  Dim rpt As AccessObject
  Dim ctl As Access.Control
  On Error Resume Next
  For Each frm In CurrentProject.AllForms
    DoCmd.OpenForm frm.name, acDesign, , , , acHidden
    For Each ctl In Forms(frm.name).Controls
       If isValidControl(ctl) Then
         If ctl.ControlSource = fldName Then
           getFieldUse = getFieldUse & "Form: " & frm.name & " Control: " & ctl.name & vbCrLf
         End If
       End If
    Next ctl
    DoCmd.Close acForm, frm.name
 Next frm
 For Each rpt In CurrentProject.AllReports
    DoCmd.OpenReport rpt.name, acViewDesign, , , acHidden
     For Each ctl In Reports(rpt.name).Controls
       If isValidControl(ctl) Then
         If ctl.ControlSource = fldName Then
           getFieldUse = getFieldUse & "Report: " & rpt.name & " Control: " & ctl.name & vbCrLf
         End If
      End If
    Next ctl
   DoCmd.Close acReport, rpt.name
 Next rpt
End Function

Public Function isValidControl(ctl As Access.Control) As Boolean
  Select Case ctl.ControlType
    Case acListBox, acComboBox, acTextBox, acComboBox
      isValidControl = True
  End Select
End Function

Public Sub FindField()
  Dim fieldName As String
  fieldName = InputBox("Enter Field Name")
  Debug.Print getFieldUse(fieldName)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top