p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 (http://p2p.wrox.com/forumdisplay.php?f=329)
-   -   VBA code to Search All Text Fields on a form (http://p2p.wrox.com/showthread.php?t=59850)

dezmond2 July 6th, 2007 02:47 PM

VBA code to Search All Text Fields on a form
 
VBA code to search all text fields on a Access form using one field as the search field. I will also need to generate a search results form and a report. Help would be greatly appreciated!
F. A. SOGGS

robcooper July 7th, 2007 11:58 AM

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.


All times are GMT -4. The time now is 08:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.