Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Cycle through controls with common names

Author(s)
Dev Ashish

(Q) I have a bunch of text box controls on form named like txtTextBox1, txtTextBox2, txtTextBox3 all the way to txtTextBox10. Can I refer to the fields from a single loop instead of explicitly referencing me!txtTextBox1, me!txtTextBox2 etc.?

(A) With forms and reports, you can reference a control by passing a string to the object. For example, the following snippet will print out the contents of all these textboxes to the Debug Window.

'***** Code Start *******
Dim i As Integer
    For i = 1 To 10
        Debug.Print Me("txtTextBox" & i).Value
    Next i '***** Code End ********

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer