Using dates during mail merge

P

Peter Jamieson

Where Graham has "date2" you need to put the name of the field in the data
source that you want to compare with (i.e. that has the date in "1st
February 2008" format)

(i.e. Graham's example has used the name "date2" where my example has used
"mydatetext", but in both cases you need to substitute the name in your data
source.)

Other than that, AFAICS, Graham's fields should work - if you change the two
{ DATE } fields in my example so that instead of looking like

{ DATE .... }

they look like

{ REF MyDate .... }

you should be there. In theory there's a typo (unusual for him :) ) in
Graham's code:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }

should have an extra quote:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy" } \o }

but in practice it works as it is.

I'd select your field codes and press F9 to re-execute them after you change
them.

--
Peter Jamieson
http://tips.pjmsn.me.uk

gjupp via OfficeKB.com said:
Many thanks for this. I tried it out but couldn't make it work. I even
tried
'tweaking' spaces and quotes (very much groping in the dark) to see it
this
would do the trick. You included 'MyDate' and 'Date2' in your construction
but I cannot understand the function of 'Date2'. It is probably this
element
that I have got wrong.

Peter Jamieson has suggested a solution that I have been able to make
work.
This is great and really deals with my oringinal request. However, it is
irritating that I have not been able to make your 'ASK' routine to
function
properly. If you have time to clarify, I shall be grateful. Please don'y
bother if you are too busy. Many thanks again.


Graham said:
It appears there were two issues that prevented this from working here as
intended

1. I was using an ASK field to collect the date to compare thus

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF {
MERGEFIELD Date2 } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate \@ "
MMMM
yyyy" }" }

Unfortunately I was using one of my test data files which also had a field
called MyDate (unused in the merge) which conflicted with the bookmark of
the same name. With that fieldname changed it worked.

2. This construction will not work for a range of dates eg

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF {
MERGEFIELD Date2 } > "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate \@ "
MMMM
yyyy" }" }

for that type of range you cannot compare dates with ordinal fields and
must
revert to the switch I posted earlier. You cannot derive a date in the
format \@ "yyyyMMdd" from a field containing ordinal text.
Seems OK in both 2003 and 2000, with or without the quotes, which
leads me to wonder whether we are attempting the same thing and/or
[quoted text clipped - 86 lines]
 
G

Graham Mayor

Re the typo - I use the macro at http://www.gmayor.com/export_field.htm to
export field contructions to avoid typos. I missed it because as you noted
it works as it stands. I was however remiss in not changing the field name
from that in my data file as this added some unwelcome confusion :(

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Peter said:
Where Graham has "date2" you need to put the name of the field in the
data source that you want to compare with (i.e. that has the date in
"1st February 2008" format)

(i.e. Graham's example has used the name "date2" where my example has
used "mydatetext", but in both cases you need to substitute the name
in your data source.)

Other than that, AFAICS, Graham's fields should work - if you change
the two { DATE } fields in my example so that instead of looking like

{ DATE .... }

they look like

{ REF MyDate .... }

you should be there. In theory there's a typo (unusual for him :) )
in Graham's code:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }

should have an extra quote:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy" } \o }

but in practice it works as it is.

I'd select your field codes and press F9 to re-execute them after you
change them.


gjupp via OfficeKB.com said:
Many thanks for this. I tried it out but couldn't make it work. I
even tried
'tweaking' spaces and quotes (very much groping in the dark) to see
it this
would do the trick. You included 'MyDate' and 'Date2' in your
construction but I cannot understand the function of 'Date2'. It is
probably this element
that I have got wrong.

Peter Jamieson has suggested a solution that I have been able to make
work.
This is great and really deals with my oringinal request. However,
it is irritating that I have not been able to make your 'ASK'
routine to function
properly. If you have time to clarify, I shall be grateful. Please
don'y bother if you are too busy. Many thanks again.


Graham said:
It appears there were two issues that prevented this from working
here as intended

1. I was using an ASK field to collect the date to compare thus

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF {
MERGEFIELD Date2 } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate
\@ " MMMM
yyyy" }" }

Unfortunately I was using one of my test data files which also had
a field called MyDate (unused in the merge) which conflicted with
the bookmark of the same name. With that fieldname changed it
worked. 2. This construction will not work for a range of dates eg

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF {
MERGEFIELD Date2 } > "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate
\@ " MMMM
yyyy" }" }

for that type of range you cannot compare dates with ordinal fields
and must
revert to the switch I posted earlier. You cannot derive a date in
the format \@ "yyyyMMdd" from a field containing ordinal text.

Seems OK in both 2003 and 2000, with or without the quotes, which
leads me to wonder whether we are attempting the same thing and/or
[quoted text clipped - 86 lines]
 
P

Peter Jamieson

Well, I suppose saying in "theory" is not quite right either given that
there is no formal specificaiton of the field language or its behaviour :)

The other thing that might be causing problems here is that, regardless of
how the DATE field nested in the ASK field is formatted, the user will need
to enter the date in the format set up in their regional options (or any
other format where the month and day are not ambiguous.

--
Peter Jamieson
http://tips.pjmsn.me.uk

Graham Mayor said:
Re the typo - I use the macro at http://www.gmayor.com/export_field.htm to
export field contructions to avoid typos. I missed it because as you noted
it works as it stands. I was however remiss in not changing the field name
from that in my data file as this added some unwelcome confusion :(

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Peter said:
Where Graham has "date2" you need to put the name of the field in the
data source that you want to compare with (i.e. that has the date in
"1st February 2008" format)

(i.e. Graham's example has used the name "date2" where my example has
used "mydatetext", but in both cases you need to substitute the name
in your data source.)

Other than that, AFAICS, Graham's fields should work - if you change
the two { DATE } fields in my example so that instead of looking like

{ DATE .... }

they look like

{ REF MyDate .... }

you should be there. In theory there's a typo (unusual for him :) )
in Graham's code:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }

should have an extra quote:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy" } \o }

but in practice it works as it is.

I'd select your field codes and press F9 to re-execute them after you
change them.


gjupp via OfficeKB.com said:
Many thanks for this. I tried it out but couldn't make it work. I
even tried
'tweaking' spaces and quotes (very much groping in the dark) to see
it this
would do the trick. You included 'MyDate' and 'Date2' in your
construction but I cannot understand the function of 'Date2'. It is
probably this element
that I have got wrong.

Peter Jamieson has suggested a solution that I have been able to make
work.
This is great and really deals with my oringinal request. However,
it is irritating that I have not been able to make your 'ASK'
routine to function
properly. If you have time to clarify, I shall be grateful. Please
don'y bother if you are too busy. Many thanks again.


Graham Mayor wrote:
It appears there were two issues that prevented this from working
here as intended

1. I was using an ASK field to collect the date to compare thus

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF {
MERGEFIELD Date2 } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate
\@ " MMMM
yyyy" }" }

Unfortunately I was using one of my test data files which also had
a field called MyDate (unused in the merge) which conflicted with
the bookmark of the same name. With that fieldname changed it
worked. 2. This construction will not work for a range of dates eg

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF {
MERGEFIELD Date2 } > "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate
\@ " MMMM
yyyy" }" }

for that type of range you cannot compare dates with ordinal fields
and must
revert to the switch I posted earlier. You cannot derive a date in
the format \@ "yyyyMMdd" from a field containing ordinal text.

Seems OK in both 2003 and 2000, with or without the quotes, which
leads me to wonder whether we are attempting the same thing and/or
[quoted text clipped - 86 lines]
 
G

Graham Mayor

The OP did say earlier in the thread that he was using UK pattern dates.

Just to clarify my original suggestion using the field name that was adopted
earlier in the thread, and restoring the missing quote ;)

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy"} \o }{ SKIPIF {
MERGEFIELD DateField } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate \@ "
MMMM
yyyy" }" }

This should work provided (as Peter indicated) {Mergefield DateField}
produces a date in the exact format
1st January 2008
ie 1[space]st[space]January[space]2008
If there is no space between 1 and st, change

{ REF MyDate \@ "d " \*Ordinal}
to
{REF MyDate \@ "d" \*Ordinal}

If you have some other format but January eg january or JANUARY you will
need more formatting switches. The match must be a true match.
http://www.gmayor.com/formatting_word_fields.htm


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Peter said:
Well, I suppose saying in "theory" is not quite right either given
that there is no formal specification of the field language or its
behaviour :)
The other thing that might be causing problems here is that,
regardless of how the DATE field nested in the ASK field is
formatted, the user will need to enter the date in the format set up
in their regional options (or any other format where the month and
day are not ambiguous.

Graham Mayor said:
Re the typo - I use the macro at
http://www.gmayor.com/export_field.htm to export field contractions
to avoid typos. I missed it because as you noted it works as it
stands. I was however remiss in not changing the field name from
that in my data file as this added some unwelcome confusion :( --
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Peter said:
Where Graham has "date2" you need to put the name of the field in
the data source that you want to compare with (i.e. that has the
date in "1st February 2008" format)

(i.e. Graham's example has used the name "date2" where my example
has used "mydatetext", but in both cases you need to substitute the
name in your data source.)

Other than that, AFAICS, Graham's fields should work - if you change
the two { DATE } fields in my example so that instead of looking
like { DATE .... }

they look like

{ REF MyDate .... }

you should be there. In theory there's a typo (unusual for him :) )
in Graham's code:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }

should have an extra quote:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy" } \o }

but in practice it works as it is.

I'd select your field codes and press F9 to re-execute them after
you change them.


Many thanks for this. I tried it out but couldn't make it work. I
even tried
'tweaking' spaces and quotes (very much groping in the dark) to see
it this
would do the trick. You included 'MyDate' and 'Date2' in your
construction but I cannot understand the function of 'Date2'. It is
probably this element
that I have got wrong.

Peter Jamieson has suggested a solution that I have been able to
make work.
This is great and really deals with my oringinal request. However,
it is irritating that I have not been able to make your 'ASK'
routine to function
properly. If you have time to clarify, I shall be grateful. Please
don'y bother if you are too busy. Many thanks again.


Graham Mayor wrote:
It appears there were two issues that prevented this from working
here as intended

1. I was using an ASK field to collect the date to compare thus

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF
{ MERGEFIELD Date2 } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF
MyDate \@ " MMMM
yyyy" }" }

Unfortunately I was using one of my test data files which also had
a field called MyDate (unused in the merge) which conflicted with
the bookmark of the same name. With that fieldname changed it
worked. 2. This construction will not work for a range of dates eg

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }{ SKIPIF
{ MERGEFIELD Date2 } > "{ REF MyDate \@ "d " \*Ordinal}{ REF
MyDate \@ " MMMM
yyyy" }" }

for that type of range you cannot compare dates with ordinal
fields and must
revert to the switch I posted earlier. You cannot derive a date in
the format \@ "yyyyMMdd" from a field containing ordinal text.

Seems OK in both 2003 and 2000, with or without the quotes, which
leads me to wonder whether we are attempting the same thing
and/or
[quoted text clipped - 86 lines]
 
G

gjupp via OfficeKB.com

Yes, this works fine, and I think that I (just about) understand HOW it works.
So now I have 2 solutions to my orignal query. Gentlemen, many thanks indeed
for sparing the time to sort this out. We now have a 'system' that is
comfortable to use and more than adequately meets our needs. It's just great


Graham said:
The OP did say earlier in the thread that he was using UK pattern dates.

Just to clarify my original suggestion using the field name that was adopted
earlier in the thread, and restoring the missing quote ;)

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy"} \o }{ SKIPIF {
MERGEFIELD DateField } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF MyDate \@ "
MMMM
yyyy" }" }

This should work provided (as Peter indicated) {Mergefield DateField}
produces a date in the exact format
1st January 2008
ie 1[space]st[space]January[space]2008
If there is no space between 1 and st, change

{ REF MyDate \@ "d " \*Ordinal}
to
{REF MyDate \@ "d" \*Ordinal}

If you have some other format but January eg january or JANUARY you will
need more formatting switches. The match must be a true match.
http://www.gmayor.com/formatting_word_fields.htm
Well, I suppose saying in "theory" is not quite right either given
that there is no formal specification of the field language or its
[quoted text clipped - 99 lines]
 
G

gjupp via OfficeKB.com

Many thanks again for your further input. It is much appreciated. Please also
see my final post to Graham Mayor.

Peter said:
Where Graham has "date2" you need to put the name of the field in the data
source that you want to compare with (i.e. that has the date in "1st
February 2008" format)

(i.e. Graham's example has used the name "date2" where my example has used
"mydatetext", but in both cases you need to substitute the name in your data
source.)

Other than that, AFAICS, Graham's fields should work - if you change the two
{ DATE } fields in my example so that instead of looking like

{ DATE .... }

they look like

{ REF MyDate .... }

you should be there. In theory there's a typo (unusual for him :) ) in
Graham's code:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy} \o }

should have an extra quote:

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy" } \o }

but in practice it works as it is.

I'd select your field codes and press F9 to re-execute them after you change
them.
Many thanks for this. I tried it out but couldn't make it work. I even
tried
[quoted text clipped - 44 lines]
 
G

Graham Mayor

You are welcome :)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Yes, this works fine, and I think that I (just about) understand HOW
it works. So now I have 2 solutions to my orignal query. Gentlemen,
many thanks indeed for sparing the time to sort this out. We now have
a 'system' that is comfortable to use and more than adequately meets
our needs. It's just great


Graham said:
The OP did say earlier in the thread that he was using UK pattern
dates.

Just to clarify my original suggestion using the field name that was
adopted earlier in the thread, and restoring the missing quote ;)

{ ASK MyDate "Start Date" \d { Date \@ "dd/MM/yyyy"} \o }{ SKIPIF {
MERGEFIELD DateField } <> "{ REF MyDate \@ "d " \*Ordinal}{ REF
MyDate \@ " MMMM
yyyy" }" }

This should work provided (as Peter indicated) {Mergefield DateField}
produces a date in the exact format
1st January 2008
ie 1[space]st[space]January[space]2008
If there is no space between 1 and st, change

{ REF MyDate \@ "d " \*Ordinal}
to
{REF MyDate \@ "d" \*Ordinal}

If you have some other format but January eg january or JANUARY you
will need more formatting switches. The match must be a true match.
http://www.gmayor.com/formatting_word_fields.htm
Well, I suppose saying in "theory" is not quite right either given
that there is no formal specification of the field language or its
[quoted text clipped - 99 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top