• Get first letter of mergefield result? (Word 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Get first letter of mergefield result? (Word 2000)

    Author
    Topic
    #417826

    Is it possible, using fields, to determine the first character of a mergefield result? For example, if a field’s result is “A123”, is it possible to construct a set of fields that will return only “A”?

    A bit of background: my company gives each client an alphanumeric code, such as (you guessed it) A123. Data for each separate client is stored in its own folder named with that code, which are further sorted into alphabetical folders (so the folder tree is something like clientsAA123).

    A merge document I’m setting up will include the code as a field in the data source, and I’m trying to set up an includetext field that will find a particular document in each client’s folder. So I will eventually need a field something like { INCLUDETEXT “L:ClientsAA123form.doc” } where the “A” and the “A123” will be determined by the data source. But unless I can get the initial letter from the client’s code, I think the whole idea is sunk. I know it’s easy to do this with VBA, but I can’t use VBA in this particular case — it has to happen as part of the merge process.

    Any thoughts?

    Thanks!

    Viewing 1 reply thread
    Author
    Replies
    • #938554

      What is the data source of the mail merge? If it is an Access table or query or an Excel worksheet (for example), you could add a calculated column that extracts the first letter of the client field.

    • #938563

      Hi Cris,

      You can do this with a mailmerge, using field coding like:
      {INCLUDETEXT “L:/ Clients/{IF{MERGEFIELD DataName} = “A*” A {IF{MERGEFIELD DataName} = “B*” B {IF{MERGEFIELD DataName} = “C*” C {IF{MERGEFIELD DataName} = “D*” D {IF{MERGEFIELD DataName} = “E*” E {IF{MERGEFIELD DataName} = “F*” F G}}}}}}/{MERGEFIELD DataName}/Form.Doc” !}

      The above example tests for a prefix of A-F and assumes G if none of these is true. You can nest up to 20 IF tests like this, but that’s not something I’d recommend.

      You can also test the second or subsequent characters, by prefixing the test string with question marks (eg “??A*” to test for an ‘A’ as the third character). Indeed, you can also test strings this way (eg “AA*” or “??AA*”)

      Cheers
      PS: You’ll note that I’ve used ‘/’ for the path separators, instead of ”. This works just as well, and is shorter.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #939075

        Our data source is a simple text file, so we unfortunately won’t be able to do any fiddling with it via Excel or Access. I think we are going to end up just adding a field for the Includetext path to the data file, so I can set it up like {INCLUDETEXT “{MERGEFIELD docpath}” }, and deal with the problem elsewhere. Thanks for the tips about the * wildcard and forward slashes, though, they will come in handy elsewhere.

    Viewing 1 reply thread
    Reply To: Get first letter of mergefield result? (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: