Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 6th, 2007, 02:47 PM
Registered User
 
Join Date: Nov 2005
Location: WASHINGTON, DC, USA.
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!
F. A. SOGGS
Reply With Quote
  #2 (permalink)  
Old July 7th, 2007, 11:58 AM
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:33 AM.


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