Solved

VBA to display text based on a merge field value

Posted on 2004-10-20
3
454 Views
Last Modified: 2012-08-14
In a mail merge document, I have a word "if" field that is setup as follows:
      Field name: EmployeeStatus  (this is a merge field)
      Comparison: Equal to
      Compare to: "N"
      Insert this text: "Non Exception"
      Otherwise insert this text: "Exception"

This works great except now I need to expand it so additional values for EmployeeStatus can be handled.  The next step (I am guessing) is to add a vba subroutine to contain a case statement something like:

Sub ConvertStatus()
      Select Case ActiveDocument.FormField.EmployeeStatus
               Case "N"
                     ActiveDocument.FormField.StatusText = "Non Exception"
               Case "E"
                        ActiveDocument.FormField.StatusText = "Exception"
               Case "X"
                        ActiveDocument.FormField.StatusText = "Exempt"
               Case "T"
                        ActiveDocument.FormField.StatusText = "Terminated"
               Case "R"
                     ActiveDocument.FormField.StatusText = "Retired"
      End Case
End Sub


Is this possible? or is the a better solution? I new to using vba with Word and need help. Any suggestions or comments would be greatly appreciated.

Thank you,
Cheri
0
Comment
Question by:LambchopAZ
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 12362787
You can nest IF fields, so you don't need VBA
{IF EmployeStatus  = "N" "Non Exception" { IF EmployeeStatus  = "E" "Exception" { IF EmployeeStatus  = "X" "Exempt"...      }}}}}
 
Use ctrl-F9 to insert the field delimeters (displayed as parentheses)
0
 

Author Comment

by:LambchopAZ
ID: 12363103
GrahamSkan:

Thank you so so much for your GREAT & quick answer.  You have really helped me out with this.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12363180
Thanks Cheri,

Your appreciation is most welcome

Graham
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question