Adding buttons to userforms

andyh69uk

New Member
Joined
Nov 23, 2005
Messages
31
I am trying to write some code that will add a command button to a userform, I am trying to achieve the following:-

Userform1 containing 1 button to close userform1
Userform2 containing 1 button to close userform2 and open userform1
Userform3 containing 1 button to close userform 3 and open useform1, but also to add another button to useform1 which will re-open userform3

Think that makes sense, I have tried various ways and got it working by adding code to the activate event off userform1 based on a varibale set by the button on userform3. This worked but I couldn't define any action for the button, if I added the code in the intialise event of userform1 the button did not get added. I tried repaint and put msgbox's in the code to check it was executing and everying seemed fine apart from the lack of any button.

Any ideas??

Cheers

Andy
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Do you want code to use the buttons as you indicated or do you want code to actually build UserForms and Buttons by code?
 

andyh69uk

New Member
Joined
Nov 23, 2005
Messages
31
I want the button on userform3 to trigger code in userform1 that adds a button at runtime.
 

andyh69uk

New Member
Joined
Nov 23, 2005
Messages
31
I have just had a thought and think that maybe it would be better to have the button exist in the first place and just set its visibility to false. Then make it appear if a varibale has been set. Is there anyway in VBA to have different constructors for userforms, by that I mean different ways to call a form. ie if userform2 calls userform1 do this.......however if userform3 calls userform1 do this..............I suppose I mean can you have different intialise events???
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
Andy

Have you tried using the Visible property of the buttons you are adding to the userform(s)?

By the way what are you actually trying to achieve?
 

andyh69uk

New Member
Joined
Nov 23, 2005
Messages
31
Sorry wasn't thinking very straight last night, obviously I can create different constructors I just need to write them as procedures to call the userform. I have used the visible setting on the button to achieve the result I required.
 

Forum statistics

Threads
1,171,885
Messages
5,878,041
Members
433,313
Latest member
Excelnoob69

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top