Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Mail Merge Test field - Insert Text

Status
Not open for further replies.

ShadowFox333

Programmer
Oct 15, 2002
97
US
Doing a Mail Merge to a letter.
input field contains 1, or 2 or 3 or 4.
I want to print one of four description's based on input field code.
If 1 print "yes" if 2 print "no" if 3 print "maybe" if 4 print "whatever".
Not a simple if..then..else. VBA,Macro???
TIA Bob
 

Code:
Select Case InputBox("Input 1, 2, 3, or 4")
    Case 1:        MsgBox "Yes"
    Case 2:        MsgBox "No"
    Case 3:        MsgBox "Maybe"
    Case 4:        MsgBox "What Ever"
    Case Else:      MsgBox "Invalid entry"
End Select

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
The code is contained within the mail merge source (merge field).
What syntax do I use to use case to test a mail Merge field.
Each letter will have a different code to convert to text.
 
Sinve this is a 'VBA Visual Basic for Application' forum,
do you have any VBA code to show us what you have so far?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
A mailmerge cannot conditionally print something according to what is contained in a data field. A field code can, of course, test the contents of a data field and conditionally output some content into the mailmerge output document. For example:
{IF{MERGEFIELD MyField}= 1 "yes" {IF{MERGEFIELD MyField}= 2 "no" {IF{MERGEFIELD MyField}= 3 "maybe" "whatever"}}}
or:
{IF«MyField»= 1 "yes" {IF«MyField»= 2 "no" {IF«MyField»= 3 "maybe" "whatever"}}}
But none of this has anything to do with VBA.

Note: The field brace pairs (i.e. '{ }') for the above examples are created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practicable to add them via any of the standard Word dialogues. Likewise, you can't type or copy & paste the chevrons (i.e. '« »') - they're part of the actual mergefields, which you can insert from the mailmerge toolbar. The spaces represented in the field construction are all required.

Cheers
Paul Edstein
[MS MVP - Word]
 
Thanks - I was able to create a nested IF statement to fix my problem but I was hoping to cerate a
VBA function or Case statement to generate the description. In some cases I may have maybe 40 or 50 description's based on a code coming in on a xlsx file. That way I just need to modify or create a single statement each time there is a code change or addition. I kind of understand VBA programming per say but I don't know how to find the proper syntax. Do I need to move the field to a variable first then test and how do I get the result back to the form. I sounds simple but I have no examples of working with the Field data. This is a mail merge that prints variable data on a letter based on input codes from the xlsx.

Thanks Bob


The only constant in the universe is change...
 
I was hoping to cerate a
VBA function or Case statement to generate the description. In some cases I may have maybe 40 or 50 description's based on a code coming in on a xlsx file. ... I kind of understand VBA programming per say but I don't know how to find the proper syntax.
It seems you're not really paying attention to what I wrote:
But none of this has anything to do with VBA.
A mailmerge cannot cause VBA to do anything. That, in turn, means you can't use VBA If & Case statements. You could, of course, run a mailmerge via VBA, but that is an entirely different proposition and, if you're using VBA, you might not even use field coding for your conditional output.

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top