Solved

VBA to display text based on a merge field value

Posted on 2004-10-20
3
452 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
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 …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now