VBA Code to search all textboxes in an Access 2010 database


Sub DoIt()
 Call fnTextBoxDefaultSearch("=CurrentUser")
End Sub

Public Function fnTextBoxDefaultSearch(sSearch As String)
' Search text boxes on all forms for =CurrentUser() function etc
 Dim frm As AccessObject
 Dim ctl As Control
 Dim sFormName As String

 For Each frm In CurrentProject.AllForms
  sFormName = frm.Name
  DoCmd.OpenForm sFormName, acDesign

 For Each ctl In Forms(sFormName)
  If ctl.controltype = 109 Then
  If InStr(1, ctl.Properties("DefaultValue"), sSearch) Then
  	Debug.Print _
  	"** " & sFormName & " - " & ctl.Name & " - " & " _
  	ControlSource->" & ctl.ControlSource
  End If
  End If
 Next

 DoCmd.Close acForm, sFormName
 Next

 End Function