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"
Private Sub MakeNewTextBox() Dim newTextBox As TextBox Dim ControlTop As Long With LastAirport ControlTop = 30 End With Set newTextBox = Me.Controls.Add("Forms.TextBox.1", "txtNextAirport", True) With newTextBox .Left = 20 .Top = ControlTop + 3 .Height = 15 .Text = txtAPID.Text End With End Sub Private Function LastAirport() As Control Set LastAirport = Me.Controls("txtAPID") End Function Private Sub cmdAddAirport_Click() If Me.txtAPID.Text = "" Then Me.txtAPID.SetFocus Else MakeNewTextBox Me.txtAPID.Text = "" Me.txtAPID.SetFocus End If End Sub
Any suggestinos/corrections would be greatly appreciated.
Thanks in advance.