Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2019, 07:32 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 01-08-2019, 01:28 PM
macropod's Avatar
macropod macropod is offline Multiple IF THEN ELSE form Windows 7 64bit Multiple IF THEN ELSE form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 01-10-2019, 08:08 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default

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?
Reply With Quote
  #4  
Old 01-10-2019, 01:33 PM
macropod's Avatar
macropod macropod is offline Multiple IF THEN ELSE form Windows 7 64bit Multiple IF THEN ELSE form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 01-11-2019, 08:55 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 01-11-2019, 09:34 AM
Charles Kenyon Charles Kenyon is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #7  
Old 01-11-2019, 09:58 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default

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.
Reply With Quote
  #8  
Old 01-11-2019, 10:12 AM
Charles Kenyon Charles Kenyon is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,125
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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:
Then test a copy of your mapped ComboBox in an IF Field for the condition you want to result in display of your text. Note that IF fields are case-sensitive. Use an AutoText field as your truetext result in the IF field.

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.
Reply With Quote
  #9  
Old 01-11-2019, 01:53 PM
macropod's Avatar
macropod macropod is offline Multiple IF THEN ELSE form Windows 7 64bit Multiple IF THEN ELSE form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #10  
Old 01-14-2019, 08:00 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default

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
Reply With Quote
  #11  
Old 01-14-2019, 12:56 PM
macropod's Avatar
macropod macropod is offline Multiple IF THEN ELSE form Windows 7 64bit Multiple IF THEN ELSE form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #12  
Old 01-15-2019, 03:38 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default

Awesome. Thanks, Paul.
When you say a document variable, what exactly do you mean?


Cheers
Reply With Quote
  #13  
Old 01-15-2019, 04:27 AM
macropod's Avatar
macropod macropod is offline Multiple IF THEN ELSE form Windows 7 64bit Multiple IF THEN ELSE form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See: https://support.microsoft.com/en-us/...word-documents
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 01-15-2019, 04:54 AM
VisionAvenger VisionAvenger is offline Multiple IF THEN ELSE form Windows 10 Multiple IF THEN ELSE form Office 2013
Novice
Multiple IF THEN ELSE form
 
Join Date: Mar 2016
Posts: 16
VisionAvenger is on a distinguished road
Default

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.
Reply With Quote
  #15  
Old 01-15-2019, 04:58 AM
macropod's Avatar
macropod macropod is offline Multiple IF THEN ELSE form Windows 7 64bit Multiple IF THEN ELSE form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Correct - a document variable could hold the equivalent of pages of (unformatted) text.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

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
Multiple IF THEN ELSE form Way to save all attachments form multiple emails at once Joey Cheung Outlook 1 12-06-2014 04:12 AM
Multiple IF THEN ELSE form 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
Multiple IF THEN ELSE form form a database from multiple sheets udea Excel 1 04-25-2011 02:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft