Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning events to runtime-created controls - is it possible? BizMark Excel Discussion (Misc queries) 1 November 20th 06 09:36 AM
Events for controls created on the fly on a userform John Austin[_3_] Excel Programming 3 March 7th 05 04:23 PM
Problem with looping through userform controls Jeremy Gollehon[_2_] Excel Programming 5 February 17th 05 05:41 PM
Help please with UserForm controls sa3214 Excel Programming 4 July 2nd 04 03:00 AM
Add controls to UserForm Vyyk Drago Excel Programming 3 August 26th 03 01:22 PM


All times are GMT +1. The time now is 02:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"