Wrox Programmer Forums
BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3
This is the forum to discuss the Wrox book Access 2007 VBA Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Armen Stein; ISBN: 9780470047033
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 6th, 2007, 02:47 PM
Registered User
Join Date: Nov 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!
Old July 7th, 2007, 11:58 AM
Wrox Author
Join Date: May 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts

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
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.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Text Fields in a Tabular Form Nadine Access VBA 2 January 17th, 2007 01:57 PM
Global Search&Replace Text in all fields in sql db buddyz SQL Server 2000 10 September 14th, 2006 08:24 AM
Search/Update in multiple worksheets VBA code help utalwalk Excel VBA 1 April 19th, 2006 04:42 AM
VBA Script to search fields and display contents Jwill1014 Access VBA 8 June 2nd, 2005 07:33 AM
Word VBA - Text Form Field dkr72 Excel VBA 1 December 22nd, 2004 11:09 AM

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