Text from Dynamic TextBox

PKwasu96

New Member
Joined
Mar 14, 2021
Messages
2
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi there,

I have one question about dynamic TextBox.
I wrote two different functions, which adding to MultiPage two different TextBoxes - first function adding TextBox in one column and fill up automatically with letters and numbers (red frame on picture), second function adding an empty TextBox, where I want to put my comments (green frame on picture). On MultiPage I put one TextBox for counting, how much TextBox I want to fill.

I want to have a text from TextBoxes from first column (red frame) in first range A and a text from TextBoxes from second column (green frame) in range B in new file.
I wrote the function to find a right text from dynamic TextBox, but the problem is, that the exported text is always only from TextBoxes in green frame.
Can someone explain me, how can I export text also from the TextBoxes in red frame?

Code of adding dynamic TextBox:
VBA Code:
Sub ShowNewTextBox(ByRef Window As MSForms.TextBox, Typ As Integer, Optional ByVal AddWindow As Boolean = False)
 
Dim DefaultText As String
Dim MinValue As Integer

Select Case Typ
    Case 1
        DefaultText = "K"
    Case Else
        DefaultText = ""
End Select
    
MinValue = Window.Tag + 1

Dim Ctrl As Control
Dim TopPos As Double

TopPos = Window.Top + 20 * MinValue

For i = MinValue To Window.Value
With WindowApp.Controls
 
If AddWindow Then
    Set Ctrl = UserForm1.MultiPage1.Page1.Add("Forms.TextBox.1", Window.Name + CStr(i))
    With Ctrl
        .Width = 32
        .Height = 16
        .Top = TopPos
        .Left = 6
        .Value = DefaultText + CStr(10 + i)
        .MaxLength = 4
        .ZOrder (0)
    End With
End If

If AddWindow Then
    Set Ctrl = UserForm1.MultiPage1.Page1.Add("Forms.TextBox.1", Window.Name + CStr(i))
    With Ctrl
        .Width = 240
        .Height = 16
        .Top = TopPos
        .Left = 44
        .MaxLength = 50
        .ZOrder (0)
    End With
End If

TopPos = TopPos + 20
 
End With
Next i

End Sub

Code of searching text in dynamic TextBox:
VBA Code:
Function FindName(Iter As Integer, Name As String) As String

Dim Text As String
Dim Ctrl As Control

For Each Ctrl In UserForm1.Controls
    If Ctrl.Name = Name Then
        Text = Ctrl.Text
    End If
Next Ctrl

FindName = Text

End Function
 

Attachments

  • UserForm.JPG
    UserForm.JPG
    35.1 KB · Views: 24

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You are using the same name for the red and green frame.
Change for green the name in: Set Ctrl = UserForm1.MultiPage1.Page1.Add("Forms.TextBox.1", Window.Name + CStr(i)&"b")
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top