#1
|
|||
|
|||
Multiple IF THEN ELSE form
We'd like to create a document that has several variables, not just 2. For example. IF CITY = New York THEN STATE = NY, ELSEIF CITY = Seattle THEN STATE = WASHINGTON, ELSEIF This is a simple example. It might be more complicated, eg, if someone chooses X, then an entire paragraph will populate Field 2, and it would have select from maybe a dozen different paragraphs, assuming there are a dozen options that a user can choose from. Can Word do something like this (essentially a VLOOKUP)? If not, can anyone suggest another option for helping people create forms quickly? Thanks |
#2
|
||||
|
||||
Word doesn't have anything like a VLOOKUP function. What to your IF tests consist of (e.g. field coding, VBA programming)?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
The document would be more fields/Content Controls
Eg Select an option: Combo Box option 1 Combo Box option 2 Combo Box option 3 Combo Box option 4 If CBO option 1 is chosen, enter "This block of text" If CBO option 2 is chosen, enter "This other block of text" If CBO option 3 is chosen, enter "The third block of text" etc Maybe this can be done easily with VBA or a Macro? |
#4
|
||||
|
||||
Your "The document would be more fields/Content Controls" is not consistent with the pseudo-code you posted; the former implies the possibility of field coding, yet the latter implies a userform. Please clarify.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thanks, Paul.
If possible, I'd like to add some Content Controls, so that users could select from a list of options. Based on the options they choose, the document would populate with content. Does that make sense? Cheers Brian |
#6
|
|||
|
|||
Hi, Paul is asking if you are using a userform, I believe.
You implied that you were. That is likely easier and more elegant than content controls. For lengthy or highly formatted text, I recommend using AutoText as storage for what you want and inserting the AutoText rather than directly inserting text. I do not recommend hiding/unhiding parts. |
#7
|
|||
|
|||
Hi
No. We weren't using a form. We just wanted to have a few combo boxes on a page, and based on the options selected, the document would populate with certain paragraphs of text. Sorry if I'm not explaining this well. |
#8
|
|||
|
|||
I apologize for the confusion. Microsoft has confounded all of us by naming different features/controls the same and using the term "Form" to mean all sorts of different things. It is confusing for all of us.
I would use mapped content controls for your ComboBoxes. See:
The AutoText should be stored in your document template. If the document will be separated from the template, you can lock or unlink that field upon completion of your form. The reason for using mapped controls is it saves having to bookmark the controls and use a REF fields in your IF field. Also, mapped controls update instantly which is not true of REF fields. Note that Paul knows far more about fields than just about anyone else. There are several of his tutorials on them pinned to the start of this forum. |
#9
|
||||
|
||||
See, for example:
https://www.msofficeforums.com/word-...html#post46903 and, for different elements from a selected item to be output to different content controls, see: https://www.msofficeforums.com/word-...tml#post120392 Note: You should not use content controls and formfields in the same document. They weren't designed to be used that way and trying to do so is a known source of problems.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Thanks, all. I looked at your code, Paul, and it appears to work perfectly.
Thanks so much! It's exactly what we want. Just a few questions, please 1) Is there a limit to the amount of text that can be added to the 'Drop Down List Properties', eg, is it 255 characters? 2) I assume there's no limit to the number or boxes we can create? Cheers Brian |
#11
|
||||
|
||||
Re 1: Yes, there is a limit, but that can be worked around by storing the content in, say, a document variable or a custom document property in the document template.
Re 2: Correct.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
Awesome. Thanks, Paul.
When you say a document variable, what exactly do you mean? Cheers |
#13
|
||||
|
||||
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
So, in this, then there's no limit (ie, Value:=fName)
Code:
Dim fName As String fName = "Jeff Smith" ' Set contents of variable "fName" in a document using a document ' variable called "FullName". ActiveDocument.Variables.Add Name:="FullName", Value:=fName ' Retrieve the contents of the document variable. |
#15
|
||||
|
||||
Correct - a document variable could hold the equivalent of pages of (unformatted) text.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
fields, vlookup |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating a Form Which has Multiple PrePopulated Forms Within | rx360 | Word VBA | 2 | 12-05-2017 06:45 PM |
Way to save all attachments form multiple emails at once | Joey Cheung | Outlook | 1 | 12-06-2014 04:12 AM |
Multiple Text Fields in Form | robstark | Word | 1 | 08-11-2014 11:26 AM |
make a form that can be used multiple times at once | Dsp581 | Excel | 19 | 04-05-2013 07:25 AM |
form a database from multiple sheets | udea | Excel | 1 | 04-25-2011 02:34 AM |