+ Reply to Thread
Results 1 to 4 of 4

Read all the textboxes on a form into an array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Read all the textboxes on a form into an array

    Is there an nice short way of reading all of the textbox values on a form into an array? What I am hoping for is something like:

    intCtr = 1
    For Each each txtbx in TextboxCollection
    intCtr = intCtr + 1
    txtboxArray(intCtr) = txtbx.text
    Next
    ?

    Thank-you!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Read all the textboxes on a form into an array

    Sorry there is no TextBoxCollection but there are other methods you could try.

    For example, this which uses the Controls collection of the form.
    Dim ctl As MSForms.Control
    Dim intCtr As Long
    Dim txtboxArray()
    
        For Each ctl In Me.Controls
            If TypeName(ctl) = "TextBox" Then
                Redim Preserve txtboxArray(intCtr)
                txtboxArray(intCtr) = ctl.Value
                intCtr = intCtr+1
            End If
        Next ctl
    Last edited by Norie; 04-03-2016 at 05:27 AM.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Re: Read all the textboxes on a form into an array

    Thank-you!

  4. #4
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Re: Read all the textboxes on a form into an array

    Norie -

    A little off-topic, but I noticed you Dim'd your int as long, which jogged my memory of seeing a post somewhere saying not to bother with Integer types, Dim them all as Long. Can you explain the reasoning?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Accessing an array of form textboxes
    By Bucephalus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2015, 07:46 AM
  2. Array of textboxes
    By danny2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2009, 04:19 AM
  3. Totaling 2 textboxes in a form
    By Khaos176 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2009, 02:54 PM
  4. Tab issue with form textboxes
    By raw in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2007, 10:52 PM
  5. Validation Of Textboxes In A Form
    By Ben103 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2007, 07:52 AM
  6. [SOLVED] Clear all textboxes on a form ?
    By SpookiePower in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2006, 12:10 PM
  7. Find textboxes on a form ?
    By SpookiePower in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2006, 09:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1