Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Aug 2002
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get first letter of mergefield result? (Word 2000)

    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!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get first letter of mergefield result? (Word 2000)

    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.

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Get first letter of mergefield result? (Word 2000)

    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
    [MS MVP - Word]

  4. #4
    Lounger
    Join Date
    Aug 2002
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get first letter of mergefield result? (Word 2000)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •