Solved

VBA to display text based on a merge field value

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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 …
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…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

713 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