Results 1 to 4 of 4

Thread: Creating Textbox Control Array at Runtime

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Location
    Oman
    Posts
    16

    Question

    How to make a textbox array at Runtime ?
    ie, I want to make some textboxes in arrays (say txtNAME(i) )

    I tried this method

    Set txtNAME1 = Controls.Add("VB.textbox", "txtNAME1"), it works.

    But when I give

    FOR I = 1 TO 10
    Set txtNAME(i) = Controls.Add("VB.textbox", "txtno(i)")
    NEXT

    It gives “Not a legal object Name” error message

    Anyone with a helping hand ?
    Thanks in advance

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    You need to load the new control before referencing it.

    The easiest way to do this (not always the fastest way)
    is to create a single textbox on the form at Design time,
    give it a name and an index = 0.

    Runtime:
    Code:
    Dim lngIndex As Long
    
    'The First control(0) was created at design time
    For lngIndex = 1 To 9
       Load ControlName(lngIndex)
       'Place aligning code here (Left, Top, etc.)
       ControlName(lngIndex).Visible = True
    Next
    This will create a control array of Controls 0-9
    Always looking for a better and faster way!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Location
    Oman
    Posts
    16

    Thumbs up

    Hi miben

    Thanks a lot.
    It works fine.

    Thank You

    Jaggu

  4. #4
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    No problem
    Always looking for a better and faster way!

Posting Permissions

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



Click Here to Expand Forum to Full Width