dynamic text box location on userform

maxx_daddy

Board Regular
Joined
Dec 3, 2010
Messages
74
hi all,
I have a userform that has 19 textboxes on it. I would like to enlarge the textbox when entered so as to give enough room to type a multi line answer as needed. My question is.... is there a way to reposition the text boxes below the active text box dynamically, say based on the top or bottom of the textbox above? otherwise the only way I can see to do this is this
Code:
Private Sub TextBox1_Enter()    With TextBox1
    .Top = 5
    .Height = 100
    End With
    With TextBox2
    .Top = 110
    .Height = 20
    End With
    With TextBox3
    .Top = 135
    .Height = 20
    End With
    With TextBox4
    .Top = 160
    .Height = 20
    End With
    With TextBox5
    .Top = 185
    .Height = 20
    End With
     With TextBox6
    .Top = 210
    .Height = 20
    End With
    With TextBox7
    .Top = 235
    .Height = 20
    End With
    With TextBox8
    .Top = 260
    .Height = 20
    End With
    With TextBox9
    .Top = 285
    .Height = 20
    End With
    With TextBox10
    .Top = 310
    .Height = 20
    End With
    With TextBox11
    .Top = 335
    .Height = 20
    End With
     With TextBox12
    .Top = 360
    .Height = 20
    End With
    With TextBox13
    .Top = 385
    .Height = 20
    End With
    With TextBox14
    .Top = 410
    .Height = 20
    End With
    With TextBox15
    .Top = 435
    .Height = 20
    End With
    With TextBox16
    .Top = 460
    .Height = 20
    End With
    With TextBox17
    .Top = 485
    .Height = 20
    End With
    With TextBox18
    .Top = 510
    .Height = 20
    End With
     With TextBox19
    .Top = 535
    .Height = 20
    End With
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With TextBox1
    .Height = 20
    End With
End Sub
for every textbox.
thanks for looking,

Maxx_daddy (Maxx's daddy)
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
If you put the TextBoxes in a frame with a vertical scroll you could perhaps increase the size of each box to take the Input Data, and scroll through them as required.
Just an Idea !!!!!
 

maxx_daddy

Board Regular
Joined
Dec 3, 2010
Messages
74
If you put the TextBoxes in a frame with a vertical scroll you could perhaps increase the size of each box to take the Input Data, and scroll through them as required.
Just an Idea !!!!!
that is a great idea, however for this project the inevitability is it will end up on a microsoft surface tablet and will be used out in the field for my job. the idea is to be able to see all of the tb's at a glance, but when you enter into one of the tb's it blows up (so you can voice to text in a paragraph of notes, of course) I am trying to keep all the data on a 10" screen. thanks again :)
 

jkpieterse

Well-known Member
Joined
Dec 3, 2007
Messages
965
Something like (I only added the enter event of the first 4 textboxes, you get the idea):

Code:
Sub RepositionAll(oCurCtl As Control)
    Dim oCtl As Control
    Dim bPast As Boolean
    Dim sHeight As Single
    For Each oCtl In Me.Controls
        If LCase(TypeName(oCtl)) = "textbox" Then
            If oCtl.Name <> oCurCtl.Name Then
                sHeight = sHeight + 45
                oCtl.Height = 25
            Else
                oCtl.Height = 100
                sHeight = sHeight + 45
            End If
            oCtl.Top = sHeight + 25
            If oCtl.Name = oCurCtl.Name Then
                sHeight = sHeight + 100
            End If
        End If
    Next
End Sub

Private Sub TextBox1_Enter()
    RepositionAll TextBox1
End Sub

Private Sub TextBox2_Enter()
    RepositionAll TextBox2
End Sub

Private Sub TextBox3_Enter()
    RepositionAll TextBox3
End Sub

Private Sub TextBox4_Enter()
    RepositionAll TextBox4
End Sub
 

maxx_daddy

Board Regular
Joined
Dec 3, 2010
Messages
74
Reminds me of the Samsung commercial (poking fun at the i-phone) where the guys mind was blown.......... yeah, that's me, right now. Amazing work........ and thank you.
Joe
 

jkpieterse

Well-known Member
Joined
Dec 3, 2007
Messages
965
You're welcome.

NB: the line "Dim bPast As Boolean" should be removed.
 

Forum statistics

Threads
1,082,344
Messages
5,364,810
Members
400,814
Latest member
gangstar67

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top