0

Basically I have a userform with textboxes for input from the user. If the user needs more rows of boxes, they can generate them based on how many they need. I want the generated rows to share the same events as the default ones. For example:

For X = 1 To n
     Set TextBoox1 = MultiPage1.Pages(2).Controls.Add("Forms.TextBox.1", "extrabox" & (X), 1)
            
            With TextBoox1
                .Width = textbox5.Width
                .Height = textbox5.Height
                .Top = textbox5.Top + (X * (textbox5.Top - textbox4.Top))
                .Left = textbox5.Left
                .Visible = False
                
            End With
Next X

This is part of a bigger script which loops through X to generate the proper number of rows in the userform. It adds these to the specified page in a multipage, and sets it to an equal height as the default textboxes (there are 5), with an appropriate placement on the screen. Now I want to give it the following properties without needing to know ahead of time how many rows the user will create:

Private Sub extrabox1_Change()

extrabox1.Value = UCase(extrabox1.Value)

End Sub

I am wondering if these events can be set dynamically at runtime somehow. Even if I have to set all textboxes in the entire userform to be uppercase, that would be fine too.

Patrick
  • 11
  • 2
  • If each addition is identical, you might want to look into adding a sub-form instead of a batch of textboxes. I've never tried to add a sub-form programmatically, but it should be pretty straight-forward and would give you all the events you need. – Frank Ball Jul 17 '23 at 19:39
  • 2
    Usually you would need to subclass into a Class Module with event handling which allows you to then handle the subsequent events. An example is in the following Q/A: https://stackoverflow.com/q/44509112/3688861 – Tragamor Jul 17 '23 at 19:46
  • 1
    @Tragamor It took a second to adapt it, but that example worked! Thank you! I don't have any way to select your comment as an answer though...? – Patrick Jul 17 '23 at 20:20
  • If you found a linked answer useful, you can always upvote it... – Tragamor Jul 18 '23 at 00:25
  • I genuinely don't think I can upvote because I have too little reputation on this exchange. I just see floating numbers next to comments and flags... – Patrick Jul 18 '23 at 20:24

0 Answers0