简体   繁体   English

将表单复制到新的多页后重命名表单上的文本框

[英]Rename TextBoxes on Form after Copying it into a new multipage

I'm dealing with this issue.我正在处理这个问题。 I have a userform that addapts after the user enters a value (for example, if he wants to add 3 members, the user form creates 3 different pages with the same boxes, after renaming them).我有一个在用户输入值后添加的用户表单(例如,如果他想添加 3 个成员,用户表单在重命名它们后会创建 3 个具有相同框的不同页面)。

I have this right now:我现在有这个:

例子

After pressing "Lanzar", the userform will create more pages with "Datos Educando 2", "Datos Educando 3"... and so on, taking the value introduced on "Educandos a inscribir:"按下“Lanzar”后,用户窗体将创建更多带有“Datos Educando 2”、“Datos Educando 3”...等的页面,采用“Educandos a inscribir”中引入的值:

The code is the following:代码如下:

Private Sub lanzar_numero_educandos_Click()
    
    Dim l As Double, r As Double
    Dim ctl As Control
    
    Me.MultiPage1.Pages(1).Visible = True
    
    If Me.MultiPage1.Pages.Count > 2 Then
    
        For a = Me.MultiPage1.Pages.Count - 1 To 2 Step -1
        
            Me.MultiPage1.Pages.Remove a
        
        Next a
    
    End If
    
    Me.MultiPage1.Pages(1).Visible = True
    
    If educandos_a_inscribir.Value <> 1 Then
    
        For a = 1 To educandos_a_inscribir.Value
        
            MultiPage1.Pages.Add
            MultiPage1.Pages(a).Controls.Copy
            MultiPage1.Pages(a + 1).Paste
            
            For Each ctl In MultiPage1.Pages(a).Controls
                If TypeOf ctl Is MSForms.Frame Then
                    l = ctl.Left
                    r = ctl.Top
                    Exit For
                End If
            Next
        
            For Each ctl In MultiPage1.Pages(a + 1).Controls
                If TypeOf ctl Is MSForms.Frame Then
                    ctl.Left = l
                    ctl.Top = r
                    Exit For
                End If
            Next
            
            Me.MultiPage1.Pages(a + 1).Caption = "Datos Educando " & a
        
        Next a
        
        Me.MultiPage1.Pages(1).Visible = False
        
    End If

End Sub

Now, the problem I have is that the pages generated with this code have random names on each TextBox, so I'm not able to locate the information introduced from the user.现在,我遇到的问题是使用此代码生成的页面在每个 TextBox 上都有随机名称,因此我无法找到用户介绍的信息。

For example, this is the first page (the one that has the names I already know):例如,这是第一页(我已经知道名字的那一页):

第二个例子

Here, the TextBox "Nombre Educando" is called "nombre_educando_1", so I can locate it easily on code:在这里,文本框“Nombre Educando”被称为“nombre_educando_1”,所以我可以很容易地在代码中找到它:

文本框名称

The Textboxes created when copying the first page, have random names (like "TextBox 34", "TextBox 35"... and so on), so I'm not able to controll how are they called.复制第一页时创建的文本框具有随机名称(例如“TextBox 34”、“TextBox 35”……等等),所以我无法控制它们的名称。

There is a way of generate the pages editing the TextBox names?有一种方法可以生成编辑 TextBox 名称的页面吗? Like, for example, for the second page generated, the TextBox in the example above should be "nombre_educando_2" and so on.例如,对于生成的第二个页面,上例中的 TextBox 应该是“nombre_educando_2”等等。

Thanks!谢谢!

Each control on the first page has an attribute named Tag .第一页上的每个控件都有一个名为Tag的属性。 You can value these with unique and meaningful values.您可以使用独特且有意义的值来评估这些。 When you paste the controls to the new page the Tag values will follow.当您将控件粘贴到新页面时,标签值将跟随。 Then as you loop through the controls on any page, use a Select Ctl.tag statement to identify what to do with the value of the control.然后,当您遍历任何页面上的控件时,使用Select Ctl.tag语句来确定如何处理控件的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM