VBA Click option on a Combobox to another userform

MFish

Board Regular
Joined
May 9, 2019
Messages
76
Hi,

What I'm trying to complete is this -
I have a combobox1 that has data, "1-1", "1-2", etc. and within this same user form (userform1) there is 3 different option buttons to choose from.
I want to write a code that executes this...

I want to show userform2 when I choose optionbutton1, no matter the selection of combobox data, 1-1, 1-2, etc.
Show userform2 when I choose optionbutton2, "..."
Show userform3 when I choose optionbutton3, "..."

Please note I want this action to happen AFTER I have selected data in the combobox, not when I click on the optionbutton1. Possible?

Now, my question to you beyond this... If I want to build a multi-layer "Open this form", to "Open that form" will my existing form "save" the information before moving on?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Please define what you mean by "Save"? As long as you simply hide it, the form selections will remain unchanged and you will be able to reference the information by control. (ie: myVar = userform.label.caption). If the form is unloaded then no, it will drop any information; You will want to pass your values from the form before you unload it to the next form as you load it up.
 
Last edited:
Upvote 0
Please define what you mean by "Save"? As long as you simply hide it, the form selections will remain unchanged and you will be able to reference the information by control. (ie: myVar = userform.label.caption). If the form is unloaded then no, it will drop any information; You will want to pass your values from the form before you unload it to the next form as you load it up.

Hi Steve_,

Thanks for your response. I've been noticing it does "Save" the information on the past userform before opening the next userform. I don't have a code that unloads anything, besides a commandbutton2 that's a clear function.
I have figured out my question, above, with showing an additional userform off a selection in a combobox and/or optionbutton. Was playing around with it and figured it out. Now, I have a follow up question...
After I fill out a userform and hit submit and it brings up the previous userform... Is it possible to pull the data from the second userform onto the first one? I just need a way for the textbox to reference a certain userform, within the workbook, to pull the data from.
Code:
sub textbox1()

if textbox1.value (within userform2 - Don't know how to reference another userform) = "" then textbox1.value = ""
end if
if textbox1.value (within userform2) = "*" then textbox1.value = "*"
end if
end sub

What I'm trying to accomplish... I want the textbox to copy the information from another textbox on ANOTHER userform.
 
Upvote 0
Fully qualify your textboxes when you reference them.

sub textbox1()

if USERFORM2.textbox1.value = "" then USERFORM1.textbox1.value = ""
'(You do not need to use end if when your if/then statement is only one line.)

if USERFORM2.textbox1.value = "*" then
USERFORM1.textbox1.value = "*"
end if '(This is when end if is needed. See how my If/Then are multiple lines?)
end sub
 
Last edited:
Upvote 0
Thanks Steve,

Now, as long as all of my Userforms are named uniquely, then any of my textboxes will know which one to pull information from? No matter how many userforms I may have?
 
Upvote 0
As long as you fully qualify the textboxes when you refer to them, yes. userformName.controlName.propertyDesired. (Ie: UserForm1.Textbox1.Text)
 
Last edited:
Upvote 0
I see you have been asking a lot of questions about UserForms lately.
I do not mean to be too noisy but would you care to explain what your ultimate Goal here is.

I have been using UserForms for years and never needed more then one to perform a task or more then one task.

Have you ever used UserForm Multipages ?

A UserForm Multipage is like have numerous UserForms all in the same UserForm

Like having one Workbook with many Worksheets.

If you would like to know more about UserForm Multipages let me know and I will explain more.

A lot easier in my opinion then needing numerous UserForms.
 
Upvote 0
and also, depending on what you are doing, i normally prefer not to use any prebuilt forms at all, opting to programmatically draw and destroy my forms on the fly as needed.
I was forced to do this for a few of my projects, like my "Excel Fantasy" game I wrote (Think Final Fantasy from NES/SNES, only written in excel) which simply was too unstable with all the forms/multipages I had to use.

this is likely not a solution you are looking for though.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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