Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
![]()
Hi Andy,
You can suppress the digits in the middle of the string, but the field coding to do so is a bit complicated. That's because Word can't do maths with more than 15 digits, so a workaround is needed. Here's the code: {QUOTE{SET Data {MERGEFIELD Value}}{=INT(Data/10000000000000000)}"-****-****-" {IF{REF Data }= "*1???" 1 {IF{REF Data }= "*2???" 2 {IF{REF Data }= "*3???" 3 {IF{REF Data }= "*4???" 4 {IF{REF Data }= "*5???" 5 {IF{REF Data }= "*6???" 6 {IF{REF Data }= "*7???" 7 {IF{REF Data }= "*8???" 8 {IF{REF Data }= "*9???" 9 0}}}}}}}}} {IF{REF Data }= "*1??" 1 {IF{REF Data }= "*2??" 2 {IF{REF Data }= "*3??" 3 {IF{REF Data }= "*4??" 4 {IF{REF Data }= "*5??" 5 {IF{REF Data }= "*6??" 6 {IF{REF Data }= "*7??" 7 {IF{REF Data }= "*8??" 8 {IF{REF Data }= "*9??" 9 0}}}}}}}}} {IF{REF Data }= "*1?" 1 {IF{REF Data }= "*2?" 2 {IF{REF Data }= "*3?" 3 {IF{REF Data }= "*4?" 4 {IF{REF Data }= "*5?" 5 {IF{REF Data }= "*6?" 6 {IF{REF Data }= "*7?" 7 {IF{REF Data }= "*8?" 8 {IF{REF Data }= "*9?" 9 0}}}}}}}}} {IF{REF Data }= "*1" 1 {IF{REF Data }= "*2" 2 {IF{REF Data }= "*3" 3 {IF{REF Data }= "*4" 4 {IF{REF Data }= "*5" 5 {IF{REF Data }= "*6" 6 {IF{REF Data }= "*7" 7 {IF{REF Data }= "*8" 8 {IF{REF Data }= "*9" 9 0}}}}}}}}}} The above field coding includes 4 sets of nested IF fields. Each set of nested IF fields is a compilation 9 sets of {IF{REF Data}= "*#?" # !}, where the: €¢ field braces (i.e. '{ }') are created in paird via Ctrl-F9; €¢ '*' is a wildcard representing all numbers in the field preceding the number you're looking for; €¢ '#' is the number you're looking for; €¢ '?' is a wildcard representing each succeeding number in the field; and €¢ '!' represents the next number or nested IF test. An advantage of using the QUOTE field wrapper is that you can have paragraph marks separating the nested IF fields, to keep the layout just that bit more comprehensible, without any effect on the output. Cheers -- macropod [MVP - Microsoft Word] ------------------------- "Andy" wrote in message ... Thanks Peter, a) I am using Word 2003 SP2. 11.8106.8107. b) I can use VBA Macros, although the documents generated are in RTF format so the macros will have to be written in normal.doc, and i would then have to update normal.doc on all machines. Another method would be preferable. c) The data is being drawn from a .net application. I would prefer not to edit the source data as it already applies to several thousand records. There is no easy way to alter the source data, or the format of the source data. d) I appreciate they are not strictly merge fields but, essentially, they do the same thing for me - i'm not really sure of the ins and outs of this i'm afraid. Basically if field 200123 contains the number 1234123412341234 and my word document contains [!matter:200123], then the word document will populate 1234123412341234 when generated. The [!matter...] codes work the same way if placed inside { } braces, i do use them in conjunction with switches and field codes elsewhere for other tasks. I think that the only way to acheive what i need is to change the data AFTER it has been merged to the document. The field codes mod() etc did not work for me, they returned a *Syntax error.... Although i would prefer to avoid VBA for reasons above, is there a way of using VBA to select strings of a merged field (i.e. select char 1,2,3,4) which i could then allocate a bookmark to? Once again, thanks for your time. Andy. "Peter Jamieson" wrote: 1. It's difficult to make suggestions about how to proceed without know a bit more about how Word is getting its data and what programming options you have. e.g. a. which version of Word can you rely on? b. can you use VBA macros? c. can you modify the data source as Word sees it? (what type of data source does Word think it is dealing with I have several document templates that have reference codes (they work the same as merge field codes) d. only Merge Fields really work the same as Merge Fields. With almost any other approach, some application must be stuffing the data into the merge fields and that would typically be an opportunity to alter what is inserted. For a numeric value, you may be able to do what you want using fields and formatting switches - in this case you could start with { =int({ MERGEFIELD myfield },1000000000000) \#"0000 **** **** " }{ =mod({ MERGEFIELD myfield },10000) \#0000 } where each pair of {} are the special field brace characters you can insert using ctrl-F9. However, there can be problems working with numbers with this many digits and you should test that the mod() function in particular works with any value you throw at it. -- Peter Jamieson http://tips.pjmsn.me.uk "Andy" wrote in message ... eld differently... The software i use is web-based and all the information stored against a customer has a reference that can be used to pre-populate information on any documents generated via the application. I have several document templates that have reference codes (they work the same as merge field codes) and, when the document is generated, pick up the information stored in those fields for the particular customer i am dealing with. In some instances, for example credit card number, I only wish to display part of the merged field in my document without having to alter the stored data. i.e. Number stored 1234 1234 1234 1234 currently populated 1234 1234 1234 1234 would prefer 1234 **** **** 1234 I am using Word 2003 SP2. |
Thread Tools | |
Display Modes | |
|
|