Results 1 to 8 of 8

Thread: VBA Click option on a Combobox to another userform
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular MFish's Avatar
    Join Date
    May 2019
    Location
    California
    Posts
    70
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Click option on a Combobox to another userform

    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?

  2. #2
    Board Regular
    Join Date
    Apr 2010
    Posts
    85
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    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 by Steve_; May 17th, 2019 at 11:53 AM.

  3. #3
    Board Regular MFish's Avatar
    Join Date
    May 2019
    Location
    California
    Posts
    70
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    Quote Originally Posted by Steve_ View Post
    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.

  4. #4
    Board Regular
    Join Date
    Apr 2010
    Posts
    85
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    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 by Steve_; May 17th, 2019 at 12:17 PM.

  5. #5
    Board Regular MFish's Avatar
    Join Date
    May 2019
    Location
    California
    Posts
    70
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    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?

  6. #6
    Board Regular
    Join Date
    Apr 2010
    Posts
    85
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    As long as you fully qualify the textboxes when you refer to them, yes. userformName.controlName.propertyDesired. (Ie: UserForm1.Textbox1.Text)
    Last edited by Steve_; May 17th, 2019 at 12:38 PM.

  7. #7
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,449
    Post Thanks / Like
    Mentioned
    27 Post(s)
    Tagged
    11 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    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.
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  8. #8
    Board Regular
    Join Date
    Apr 2010
    Posts
    85
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Click option on a Combobox to another userform

    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 by Steve_; May 17th, 2019 at 04:11 PM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •