Generating Multiple Textboxes With Relative Position

  • Hello All,

    I am trying to create a form with a text box that when text is entered, it adds to the userform another textbox with that data in it. The focus then goes back to the original textbox so that more may be added indefinitely, all with relative position to the most recently added textbox.

    Here is what I have so far, works for one time, but not multiple textboxes. The original textbox is "txtAPID"

    Any suggestinos/corrections would be greatly appreciated.
    Thanks in advance.

  • Re: Generating Multiple Textboxes With Relative Position

    Try this.

    [vba]Private m_LastAirPort As msforms.TextBox
    Private Sub MakeNewTextBox()

    Dim ControlTop As Long

    If m_LastAirPort Is Nothing Then
    ControlTop = txtAPID.Top
    ControlTop = m_LastAirPort.Top + m_LastAirPort.Height + 3
    End If

    Set m_LastAirPort = Me.Controls.Add("Forms.TextBox.1", "txtNextAirport", True)

    With m_LastAirPort
    .Left = 20
    .Top = ControlTop
    .Height = 15
    .Text = txtAPID.Text
    End With

    End Sub

    Private Sub cmdAddAirport_Click()

    If Me.txtAPID.Text = "" Then
    Me.txtAPID.Text = ""
    End If

    End Sub

  • Re: Generating Multiple Textboxes With Relative Position


    Thanks for the solution. works great!!
    Exactly what I was trying to do, just didn't know the code to make it work.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!