PDA

View Full Version : Referencing multiple userforms



SLJ
12-11-2013, 09:28 AM
I am new to VBA...I have created a workbook that has multiple userforms for different types of data. For example, the main entry userform asks the user a series of Yes/No questions. If the answer is "Yes," another userform opens with a choice of option buttons. The user would repeat this for all the questions with a Yes answer (each with its own userform and set of option buttons). When back at the main entry userform, I'd like the user to click an OK button that would read all associated userforms, and apply If/Then logic based on the selected option buttons in all userforms, and then populate onto the worksheet. Is that possible, and does this question even make sense? Thank you in advance!

SamT
12-11-2013, 11:22 AM
You are describing a decision tree and an option tree. They are different Patterns.

Why? In other words, what are you trying to do, not how you are trying to do it.

In even other words, what is the goal?

In still more words: What is the condition before the desired code runs and what is the desired condition?


And yet more words: Nope. That's all the words I got :D

SLJ
12-11-2013, 11:36 AM
Thanks Sam. Like I said, I'm new to VBA and so I hope I can explain clearly. I cannot attach the exact workbook that I am working with because it is confidential, but I have attached a sample that shows an example of what I have. (Hopefully I attached correctly).

In this sample, I have three options: A, B, C on my main entry form. I would like a user to be able to choose any combination of A, B, C. When they choose "Yes" for any of the options, another userform specific to that option gives them additional choices. I would like the users to be able to pick the choice for each option A, B, C that may apply, return to the main entry userform, and click OK and have the data from ALL option forms populate into my worksheet. Make sense?

SamT
12-11-2013, 11:55 AM
If I understand what you are trying to accomplish:


Show Question.
If Yes Then
Show Options
On OptionSelect Show NextQuestion
Else
Show NextQuestion
End If

Will the Options in any Group be mutually exclusive?

Will the User need to verify the results?

Will the User ever need to back up and change their mind?

Do you have any UserForms or Code to show us? If you use the Advanced button you can upload Workbooks with the Manage Attachments (way) below the Editor.

SLJ
12-11-2013, 12:11 PM
I wish I had some userforms or code to share; the project I am working on is confidential and I am on a tight deadline so I dont have the time to remove all confidential info to upload a sample. If you are able to take a look at the sample workbook I attached previously, I can try to explain in simpler terms what I want a code to do:

User opens workbook and main userform automatically opens.
User selects "Yes" for Option A.
Option A userform opens and user selects Choice 1, clicks an OK button, and returns to the main userform.
User then selects "Yes" for Option B.
Option B userform opens and user selects Choice 3, clicks an OK button, and again returns to the main userform.
User then selects "Yes" for Option C.
Option C userform opens and user selects Choice 5, clicks an OK button, and returns to the main userform for the last time.
User then clicks an OK button on the main userform. When that OK button is clicked, I would like something to happen that can read that Choice 1 (from Option A userform), Choice 3 (from Option B userform) and Choice 5 (from Option C userform) were all selected. I was hoping a code could be written that states something like:
If OptionButtonChoice1 from OptionA_userform.value = True AND OptionButtonChoice3 from OptionB_userform.value = True AND OptionButtonChoice5 from OptionC_userform.value = True Then
Sheet1.Range("A3").Value = "2568"

I know how to write an If/Then scenario that is contained to one userform, but I would like to write a scenario that references the option buttons on different userforms.

snb
12-11-2013, 03:41 PM
Since you are new to VBA you shouldn't accept a strict deadline.

Dive into what multipage can offer you, so you can reduce the amount of userforms to 1.
Since we are not new to VBA we know it's hardly possible to give sound suggestions if you do not post a sample workbook.
In this case it's either or.

SamT
12-11-2013, 04:40 PM
Open the project workbook and a new workbook.

In the VBA Project Explorer pane left drag the Project's UserForms onto the new Workbook's "ThisWokrbook" Keyword in the Project Explorer Pane

Save and upload the new Workbook