Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Problem with userform controls created on the fly
I have trouble getting controls created on the fly at run time to work. For example the following code creates a TextBox with necessary attributes. Set x =Me.Controls.Add("Forms.TextBox.1") With x ..Top=10 ..Height=50 ..Left=6 ..Width=20 ..Name = "TextBox1" End With In addition, suppose I manually add a CommandButton (at design time) and append an event handler to it in the userform codemodule, as in: Private Sub CommandButton1_Click() TextBox1.Text ="" TextBox1.Text = "Enter Surname" End Sub I would expect that upon clicking the CommandButton, the TextBox1 should respond accordingly by getting "Enter Surname" printed. Indeed, nothing happens! However, the problem is averted when the TextBox is created at design time (even programatically) as in the code below: Then the manually crafted CommandButton and its event handler work as expected. Set x = ThisWorkBook.VBProjects.VBComponents.Designer.Cont rols.Add("Forms.TextBox1.1") With x ..Top=10 ..Height=50 ..Left=6 ..Width=20 ..Name = "TextBox1" End With Why do controls created on the fly exhibit this problem? I do know that if we programmatically use code to write event handlers about the same time as the controls are created, the event handlers so created *do work*. Which translates, in this example, to the need to create the Commandbutton and its event programatically in order for them to be functional. There seems to be no room for manual "dig" to work on "fly controls" (although they do get along with Designer-time controls). Have I gotten myself in a mental tangle? I would love to have an easier way of manipulating controls created on the fly. Any light will be welcome. David -- davidm ------------------------------------------------------------------------ davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645 View this thread: http://www.excelforum.com/showthread...hreadid=484029 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Assigning events to runtime-created controls - is it possible? | Excel Discussion (Misc queries) | |||
Events for controls created on the fly on a userform | Excel Programming | |||
Problem with looping through userform controls | Excel Programming | |||
Help please with UserForm controls | Excel Programming | |||
Add controls to UserForm | Excel Programming |