Group:  Microsoft Word » microsoft.public.word.mailmerge.fields
Thread: Truncating in Mail Merge

Geek News

Truncating in Mail Merge
Laurel 6/4/2007 2:58:02 PM
Hi All,
I'd like to print just the last 4 numbers of an account number in a mail
merge letter (front fill the rest with asterisks). It seems like it should be
just as simple as the RIGHT function in Excel but by necessity my source
document has be a CSV text document so the function has to take place in
Word. Is this possible?

Thanks so much!
Laurel
Re: Truncating in Mail Merge
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 6/4/2007 3:20:25 PM
Unfortunately there is no RIGHT function associated with Word fields. If the
field contains a number (rather than numbers and letters) then you could
cobble something together along the lines of

{ SET AB { =({ Mergefield fieldname } / 10000 ) \# "0.0000"} } ***{ =({
AB } - { =INT({ AB }) }) * 10000 }

with the number of asterisks representing the missing leading numbers, but
if it is not a simple number, you will have to edit the data file.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Laurel wrote:
[Quoted Text]
> Hi All,
> I'd like to print just the last 4 numbers of an account number in a
> mail merge letter (front fill the rest with asterisks). It seems like
> it should be just as simple as the RIGHT function in Excel but by
> necessity my source document has be a CSV text document so the
> function has to take place in Word. Is this possible?
>
> Thanks so much!
> Laurel


Re: Truncating in Mail Merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 6/4/2007 3:30:00 PM
<<
It seems like it should be
just as simple as the RIGHT function in Excel
[Quoted Text]
>>

It does, but unfortunately it isn't.

If the account number is a whole number (or in some case, contains a whole
number) not more than around 14 or so digits long, you can use

{ =mod({ MERGEFIELD youraccountfield },10000) } and prefix any asterixes you
need.

All the {} need to be the special field code braces that you can insert
using ctrl-F9.

If the account number is more complex there are two things you can do other
than transform your data source into another format:
a. use a DATABASE field - nasty, but see http://tips.pjmsn.me.uk/t0004.htm
b. use Word VBA to issue a SQL query to get the data from the .csv file,
and put the necessary right() function in that query. That isn't
straightforward either, but it can usually be done as long as the .csv can
be read by the Jet ODBC driver/OLE DB provider and doesn't have more than
255 fields.

Peter Jamieson


"Laurel" <Laurel[ at ]discussions.microsoft.com> wrote in message
news:5DF29172-C6F5-4205-85C6-EEF2D7FB78EE[ at ]microsoft.com...
> Hi All,
> I'd like to print just the last 4 numbers of an account number in a mail
> merge letter (front fill the rest with asterisks). It seems like it should
> be
> just as simple as the RIGHT function in Excel but by necessity my source
> document has be a CSV text document so the function has to take place in
> Word. Is this possible?
>
> Thanks so much!
> Laurel

Re: Truncating in Mail Merge
Laurel 6/5/2007 6:22:01 PM
Thank you so much to you and Graham. I'm having trouble getting it to work
without syntax errors. I don't have a lot of experience with mail merge. But
while I was trying to figure it out, I came across a numeric picture switch
that drops digits to the left of the "x" placeholder. I'm still unable to
type without getting syntax errors but theoretically would this work?

{ = 111053 + 111439 \# x## } displays "492". (example in documentation)
{ = «Cardholder_Number»\# x### } (how it would maybe work for me?)

Also, I'm still unable to key this into my document so that it works. I can
get the brackets using Ctrl-F9 but everything I type inside gets a syntax
error.

Thank you so much. You guys are great!

"Peter Jamieson" wrote:

[Quoted Text]
> <<
> It seems like it should be
> just as simple as the RIGHT function in Excel
> >>
>
> It does, but unfortunately it isn't.
>
> If the account number is a whole number (or in some case, contains a whole
> number) not more than around 14 or so digits long, you can use
>
> { =mod({ MERGEFIELD youraccountfield },10000) } and prefix any asterixes you
> need.
>
> All the {} need to be the special field code braces that you can insert
> using ctrl-F9.
>
> If the account number is more complex there are two things you can do other
> than transform your data source into another format:
> a. use a DATABASE field - nasty, but see http://tips.pjmsn.me.uk/t0004.htm
> b. use Word VBA to issue a SQL query to get the data from the .csv file,
> and put the necessary right() function in that query. That isn't
> straightforward either, but it can usually be done as long as the .csv can
> be read by the Jet ODBC driver/OLE DB provider and doesn't have more than
> 255 fields.
>
> Peter Jamieson
>
>
> "Laurel" <Laurel[ at ]discussions.microsoft.com> wrote in message
> news:5DF29172-C6F5-4205-85C6-EEF2D7FB78EE[ at ]microsoft.com...
> > Hi All,
> > I'd like to print just the last 4 numbers of an account number in a mail
> > merge letter (front fill the rest with asterisks). It seems like it should
> > be
> > just as simple as the RIGHT function in Excel but by necessity my source
> > document has be a CSV text document so the function has to take place in
> > Word. Is this possible?
> >
> > Thanks so much!
> > Laurel
>
Re: Truncating in Mail Merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 6/5/2007 6:43:05 PM
HI Laurel,

You're on the right track, but let's start from scratch:

1. To do it the way you propose:

Select the point where you want to enter the field in your document.

Press ctrl F9 to get

{ }

Inside that, type

= \# x###

to give you

{ = \# x### }

Click just before the backslash and use ctrl-F9 to insert another {}, to
give you

{ = { } \# x### }


then between those new {}, type

MERGEFIELD Cardholder_Number

to give you

{ = { MERGEFIELD Cardholder_Number
} \# x### }

2. To do it the way I suggested,...

Select the point where you want to enter the field in your document.

Press ctrl F9 to get

{ }

Inside that, type

=mod(,10000)

to give you

{ =mod(,10000) }

Click just before the comma and use ctrl-F9 to insert another {}, to give
you

{ =mod({ },10000) }

then between those new {}, type

MERGEFIELD "the name of your account field"

to give you

{ =mod({ MERGEFIELD "the name of your account field"
},10000) }

3. That's probably enough for you to follow Graham's suggestion as well.

Peter Jamieson


"Laurel" <Laurel[ at ]discussions.microsoft.com> wrote in message
news:90693BA1-9FB4-467E-9BEE-5895F8BFF94A[ at ]microsoft.com...
[Quoted Text]
> Thank you so much to you and Graham. I'm having trouble getting it to work
> without syntax errors. I don't have a lot of experience with mail merge.
> But
> while I was trying to figure it out, I came across a numeric picture
> switch
> that drops digits to the left of the "x" placeholder. I'm still unable to
> type without getting syntax errors but theoretically would this work?
>
> { = 111053 + 111439 \# x## } displays "492". (example in documentation)
> { = «Cardholder_Number»\# x### } (how it would maybe work for me?)
>
> Also, I'm still unable to key this into my document so that it works. I
> can
> get the brackets using Ctrl-F9 but everything I type inside gets a syntax
> error.
>
> Thank you so much. You guys are great!
>
> "Peter Jamieson" wrote:
>
>> <<
>> It seems like it should be
>> just as simple as the RIGHT function in Excel
>> >>
>>
>> It does, but unfortunately it isn't.
>>
>> If the account number is a whole number (or in some case, contains a
>> whole
>> number) not more than around 14 or so digits long, you can use
>>
>> { =mod({ MERGEFIELD youraccountfield },10000) } and prefix any asterixes
>> you
>> need.
>>
>> All the {} need to be the special field code braces that you can insert
>> using ctrl-F9.
>>
>> If the account number is more complex there are two things you can do
>> other
>> than transform your data source into another format:
>> a. use a DATABASE field - nasty, but see
>> http://tips.pjmsn.me.uk/t0004.htm
>> b. use Word VBA to issue a SQL query to get the data from the .csv file,
>> and put the necessary right() function in that query. That isn't
>> straightforward either, but it can usually be done as long as the .csv
>> can
>> be read by the Jet ODBC driver/OLE DB provider and doesn't have more than
>> 255 fields.
>>
>> Peter Jamieson
>>
>>
>> "Laurel" <Laurel[ at ]discussions.microsoft.com> wrote in message
>> news:5DF29172-C6F5-4205-85C6-EEF2D7FB78EE[ at ]microsoft.com...
>> > Hi All,
>> > I'd like to print just the last 4 numbers of an account number in a
>> > mail
>> > merge letter (front fill the rest with asterisks). It seems like it
>> > should
>> > be
>> > just as simple as the RIGHT function in Excel but by necessity my
>> > source
>> > document has be a CSV text document so the function has to take place
>> > in
>> > Word. Is this possible?
>> >
>> > Thanks so much!
>> > Laurel
>>

Re: Truncating in Mail Merge
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 6/6/2007 6:04:29 AM
I think yours looks simpler ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Peter Jamieson wrote:
[Quoted Text]
>
> 3. That's probably enough for you to follow Graham's suggestion as
> well.
> Peter Jamieson
>



Re: Truncating in Mail Merge
Laurel 6/6/2007 12:39:01 PM
{ MERGEFIELD «Cardholder_Number»\# x### } works just like the RIGHT function
in Excel and displays the last 4 digits of the cardholder number in my
letter. Simple and no math!

Thanks for your help and suggestions.
Laurel

"Laurel" wrote:

[Quoted Text]
> Thank you so much to you and Graham. I'm having trouble getting it to work
> without syntax errors. I don't have a lot of experience with mail merge. But
> while I was trying to figure it out, I came across a numeric picture switch
> that drops digits to the left of the "x" placeholder. I'm still unable to
> type without getting syntax errors but theoretically would this work?
>
> { = 111053 + 111439 \# x## } displays "492". (example in documentation)
> { = «Cardholder_Number»\# x### } (how it would maybe work for me?)
>
> Also, I'm still unable to key this into my document so that it works. I can
> get the brackets using Ctrl-F9 but everything I type inside gets a syntax
> error.
>
> Thank you so much. You guys are great!
>
> "Peter Jamieson" wrote:
>
> > <<
> > It seems like it should be
> > just as simple as the RIGHT function in Excel
> > >>
> >
> > It does, but unfortunately it isn't.
> >
> > If the account number is a whole number (or in some case, contains a whole
> > number) not more than around 14 or so digits long, you can use
> >
> > { =mod({ MERGEFIELD youraccountfield },10000) } and prefix any asterixes you
> > need.
> >
> > All the {} need to be the special field code braces that you can insert
> > using ctrl-F9.
> >
> > If the account number is more complex there are two things you can do other
> > than transform your data source into another format:
> > a. use a DATABASE field - nasty, but see http://tips.pjmsn.me.uk/t0004.htm
> > b. use Word VBA to issue a SQL query to get the data from the .csv file,
> > and put the necessary right() function in that query. That isn't
> > straightforward either, but it can usually be done as long as the .csv can
> > be read by the Jet ODBC driver/OLE DB provider and doesn't have more than
> > 255 fields.
> >
> > Peter Jamieson
> >
> >
> > "Laurel" <Laurel[ at ]discussions.microsoft.com> wrote in message
> > news:5DF29172-C6F5-4205-85C6-EEF2D7FB78EE[ at ]microsoft.com...
> > > Hi All,
> > > I'd like to print just the last 4 numbers of an account number in a mail
> > > merge letter (front fill the rest with asterisks). It seems like it should
> > > be
> > > just as simple as the RIGHT function in Excel but by necessity my source
> > > document has be a CSV text document so the function has to take place in
> > > Word. Is this possible?
> > >
> > > Thanks so much!
> > > Laurel
> >
Re: Truncating in Mail Merge
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 6/6/2007 1:36:02 PM
Of course it does! I wouldn't mind but I did a web page about this :(

http://www.gmayor.com/formatting_word_fields.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Laurel wrote:
[Quoted Text]
> { MERGEFIELD «Cardholder_Number»\# x### } works just like the RIGHT
> function in Excel and displays the last 4 digits of the cardholder
> number in my letter. Simple and no math!
>
> Thanks for your help and suggestions.
> Laurel
>
> "Laurel" wrote:
>
>> Thank you so much to you and Graham. I'm having trouble getting it
>> to work without syntax errors. I don't have a lot of experience with
>> mail merge. But while I was trying to figure it out, I came across a
>> numeric picture switch that drops digits to the left of the "x"
>> placeholder. I'm still unable to type without getting syntax errors
>> but theoretically would this work?
>>
>> { = 111053 + 111439 \# x## } displays "492". (example in
>> documentation) { = «Cardholder_Number»\# x### } (how it would maybe
>> work for me?)
>>
>> Also, I'm still unable to key this into my document so that it
>> works. I can get the brackets using Ctrl-F9 but everything I type
>> inside gets a syntax error.
>>
>> Thank you so much. You guys are great!
>>
>> "Peter Jamieson" wrote:
>>
>>> <<
>>> It seems like it should be
>>> just as simple as the RIGHT function in Excel
>>>>>
>>>
>>> It does, but unfortunately it isn't.
>>>
>>> If the account number is a whole number (or in some case, contains
>>> a whole number) not more than around 14 or so digits long, you can
>>> use
>>>
>>> { =mod({ MERGEFIELD youraccountfield },10000) } and prefix any
>>> asterixes you need.
>>>
>>> All the {} need to be the special field code braces that you can
>>> insert using ctrl-F9.
>>>
>>> If the account number is more complex there are two things you can
>>> do other than transform your data source into another format:
>>> a. use a DATABASE field - nasty, but see
>>> http://tips.pjmsn.me.uk/t0004.htm b. use Word VBA to issue a SQL
>>> query to get the data from the .csv file, and put the necessary
>>> right() function in that query. That isn't straightforward either,
>>> but it can usually be done as long as the .csv can be read by the
>>> Jet ODBC driver/OLE DB provider and doesn't have more than 255
>>> fields.
>>>
>>> Peter Jamieson
>>>
>>>
>>> "Laurel" <Laurel[ at ]discussions.microsoft.com> wrote in message
>>> news:5DF29172-C6F5-4205-85C6-EEF2D7FB78EE[ at ]microsoft.com...
>>>> Hi All,
>>>> I'd like to print just the last 4 numbers of an account number in
>>>> a mail merge letter (front fill the rest with asterisks). It seems
>>>> like it should be
>>>> just as simple as the RIGHT function in Excel but by necessity my
>>>> source document has be a CSV text document so the function has to
>>>> take place in Word. Is this possible?
>>>>
>>>> Thanks so much!
>>>> Laurel


Re: Truncating in Mail Merge
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 6/7/2007 9:18:16 AM
Unfortunately mine would also need something like \#0000 to cope with
leading zeros in the last four digits so Laurel's wins AFAICS!

Peter Jamieson
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> wrote in message
news:uR$MNCAqHHA.1144[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
>I think yours looks simpler ;)
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> Peter Jamieson wrote:
>>
>> 3. That's probably enough for you to follow Graham's suggestion as
>> well.
>> Peter Jamieson
>>
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net