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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you want code to use the buttons as you indicated or do you want code to actually build UserForms and Buttons by code?
 
Upvote 0
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???
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,952
Members
448,535
Latest member
alrossman

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
Back
Top