Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Adding Code to Command Button Added At Run Time

I have a poject with a form which has a Command Button, Text Box, and Label
control added to it at run time. It has taken me at least three hours (I'm
extremely new at programming) to figure out how to add the three controls to
my form at run time. Once I finally figured out how to do all that I
realized I didn't know how to add code to make my command button do
something. What I want to do is after my form is shown on the screen, the
label presents a question "How many text boxes do you want added to the
screen?". The user will enter the number (1 - 10) in the text box and then
hit ok. The code under that button should then remove the initial Label,
Text Box and Command Button controls, and add the specified number of text
boxes, and resize the screen according to the amount of text boxes added.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding Code to Command Button Added At Run Time

You would be better off putting everything in at design time.
Then make controls visible or visible = False at the appropriate time

So the code and controls are all in place.

Lets say you have a userform of Height 80 with textboxes already in place
but visible = false. You want to have half visible, so your code loops
through making them visible, then sets the height to 40 to "size" the
userform. The other half of the userform will be virtual - it will be as if
it doesn't exist.

Another consideration is if you try to add code and controls with code, you
won't be able to protect your project.

--
Regards,
Tom Ogilvy

"Kevin E." wrote in message
...
I have a poject with a form which has a Command Button, Text Box, and Label
control added to it at run time. It has taken me at least three hours
(I'm
extremely new at programming) to figure out how to add the three controls
to
my form at run time. Once I finally figured out how to do all that I
realized I didn't know how to add code to make my command button do
something. What I want to do is after my form is shown on the screen, the
label presents a question "How many text boxes do you want added to the
screen?". The user will enter the number (1 - 10) in the text box and
then
hit ok. The code under that button should then remove the initial Label,
Text Box and Command Button controls, and add the specified number of text
boxes, and resize the screen according to the amount of text boxes added.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Adding Code to Command Button Added At Run Time

Hi Tom,

I was searching the site for information on a control button and came across
this posting. My question is if I add a control button with code, that will
prevent me from protecting my worksheet and workbook? Is there a work around
for this. Am I left with using a macro on a custom toolbar?

Thank you

"Tom Ogilvy" wrote:

You would be better off putting everything in at design time.
Then make controls visible or visible = False at the appropriate time

So the code and controls are all in place.

Lets say you have a userform of Height 80 with textboxes already in place
but visible = false. You want to have half visible, so your code loops
through making them visible, then sets the height to 40 to "size" the
userform. The other half of the userform will be virtual - it will be as if
it doesn't exist.

Another consideration is if you try to add code and controls with code, you
won't be able to protect your project.

--
Regards,
Tom Ogilvy

"Kevin E." wrote in message
...
I have a poject with a form which has a Command Button, Text Box, and Label
control added to it at run time. It has taken me at least three hours
(I'm
extremely new at programming) to figure out how to add the three controls
to
my form at run time. Once I finally figured out how to do all that I
realized I didn't know how to add code to make my command button do
something. What I want to do is after my form is shown on the screen, the
label presents a question "How many text boxes do you want added to the
screen?". The user will enter the number (1 - 10) in the text box and
then
hit ok. The code under that button should then remove the initial Label,
Text Box and Command Button controls, and add the specified number of text
boxes, and resize the screen according to the amount of text boxes added.




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
Adding Code to Command Button at Run Time Kevin E. Excel Programming 1 September 20th 06 12:25 AM
Made a button, added code, now what? travis[_3_] Excel Programming 2 February 3rd 06 10:44 AM
Adding A Date Command Button hazey Excel Programming 4 December 12th 05 09:50 PM
Adding Code to an Existing Command Button with VBA jasoncw[_2_] Excel Programming 1 February 15th 05 11:15 PM
Adding a command button Roy Thompson Excel Programming 2 October 4th 04 10:12 PM


All times are GMT +1. The time now is 11:13 AM.

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

About Us

"It's about Microsoft Excel"