Results 1 to 2 of 2

Thread: creating textbox in runtime

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Post


    Hi!,

    On my form I have text1(0). When the user clicks a command button, another textbox is loaded below it. The code I use for this is:

    Private Sub Command1_Click()
    Static Index As Integer
    Index = Index + 1
    Load Text1(Index)
    Text1(Index).Visible = True
    Text1(Index).Move Text1(Index - 1).Left, Text1(Index - 1).Top + Text1(Index - 1).Height
    End Sub

    The user can create as many text boxes as they want.

    Now my problem is when the user clicks on a 'Showform2' button. I also have a textbox array, text2(0), on form2. I want the same number of textboxes to load on form2 as are on form1, and the contents of the textboxes on form2 to be the same as those on form1.

    The code I use at present, on the form2_load() event, is:

    Private Sub Form_Load()
    For Index = 0 To Form1.Text1().Count - 1
    Text2(Index)= Form1.Text1(Index)
    Next Index
    End Sub

    But this gives me an error: 'Control array element '1' doesn't exist'. if I create more than 1 textbox on form1.

    How can I load the same number of boxes on form2 as form1?

    Thanks for any help!

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    You were almost there!

    Code:
    Private Sub Form_Load()
    Dim index As Integer
    
    Text1(0) = Form1.Text1(0)
    For index = 1 To Form1.Text1.UBound
    
    Load Text1(index)
    Text1(index).Visible = True
    Text1(index).Move Text1(index - 1).Left, Text1(index - 1).Top + Text1(index - 1).Height
    
    Text1(index) = Form1.Text1(index)
    Next index
    
    
    
    End Sub
    Mark
    -------------------

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