I think this is what you are trying?
After you paste the control, try this
'
'~~> Rest of your code
'
MultiPage1.Pages(i).Paste
For Each ctl In Me.MultiPage1.Pages(i).Controls
If TypeOf ctl Is MSForms.TextBox Then
'~~> Your code here
ctl.Text = vID
Exit For
End If
Next
'
'~~> Rest of your code
'
Also declare this as the top of your code
Dim ctl As Control
FOLLOWUP (From Comments)
If you have multiple Controls
of the same type then I prefer not copying and pasting but recreating them from scratch. This gives me more control over those Controls
However, if you still want to use the Copy - Paste method then use the .Tag
property. See this example
Create a userform as shown in the snapshot below.
In Page(0) set tags for each textbox.
Let's use this code in the userform
Option Explicit
Dim ctl As Control
Private Sub CommandButton1_Click()
Debug.Print "Page (0):-"
For Each ctl In Me.MultiPage1.Pages(0).Controls
If TypeOf ctl Is MSForms.TextBox Then
Debug.Print ctl.Name; "==="; ctl.Tag
End If
Next
Debug.Print "---"
Debug.Print "Page (1):-"
MultiPage1.Pages(0).Controls.Copy
MultiPage1.Pages.Add
MultiPage1.Pages(1).Paste
For Each ctl In Me.MultiPage1.Pages(1).Controls
If TypeOf ctl Is MSForms.TextBox Then
Debug.Print ctl.Name; "==="; ctl.Tag
End If
Next
Debug.Print "---"
Debug.Print "Page (2):-"
MultiPage1.Pages.Add
MultiPage1.Pages(2).Paste
For Each ctl In Me.MultiPage1.Pages(2).Controls
If TypeOf ctl Is MSForms.TextBox Then
Debug.Print ctl.Name; "==="; ctl.Tag
End If
Next
End Sub
When you run the code, you will see this output in the screen
If you notice that the .Tag
doesn't change. So we can effectively use this if we have more controls. See this example
Option Explicit
Dim ctl As Control
Private Sub CommandButton1_Click()
MultiPage1.Pages(0).Controls.Copy
MultiPage1.Pages.Add
MultiPage1.Pages(1).Paste
For Each ctl In Me.MultiPage1.Pages(1).Controls
If TypeOf ctl Is MSForms.TextBox Then
Select Case ctl.Tag
Case "A"
'~~> Your code goes here to put text in this textbox
ctl.Text = "AAAA"
Case "B"
'~~> Your code goes here to put text in this textbox
ctl.Text = "BBBB"
End Select
End If
Next
End Sub
When you run it, you get
HTH