View Single Post
  #2 (permalink)  
Old July 7th, 2007, 11:58 AM
robcooper robcooper is offline
Wrox Author
 
Join Date: May 2007
Location: , Washington, .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The following code will iterate through all text boxes in the Controls collection of the form for matching text.

Sub FindInControls(frm As Form, strSearch As String)
    Dim ctl As Control

    For Each ctl In frm.Controls
        ' Limit search to text boxes
        If ctl.ControlType = acTextBox Then
            If ctl.Value = strSearch Then
                ' Print the control name and value
                ' Change this to whatever functionality you need
                Debug.Print ctl.Name, ctl.Value
            End If
        End If
    Next
End Sub

The navigation buttons at the bottom of a form in Access 2007 includes a Search box which also does this for you.

Hope this helps,

Rob Cooper
Lead Software Design Engineer in Test
Microsoft Access Team

co-author: Access 2007 VBA Programmer's Reference
co-author: Expert Access 2007 Programming

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at microsoft.com/info/cpyright.htm.