Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
walkerh walkerh is offline
external usenet poster
 
Posts: 2
Default if statements with dates in mailmerge

This has me puzzled. We have a mailmerge document populated from an external database via a header and text file. In the letter we compare a Start Date with an End Date. If they are the same the letter only prints the Start Date m/d/y. If the End Date is greater than the Start Date, we format the Start Date for month/day add a dash and format the End Date month/day/year. We just ran into a case where if the month and day are the same in the Start Date and the same in the End Date the test fails and only the Start Date is printed. An example would be SD = 04/04/2007 and ED = 06/06/2007. changing the SD to 03/03/2007 or 05/05/2007 or the ED in similiar fashion yields the same failure. A difference in the year results in the desired behavior. Any thoughts?

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default if statements with dates in mailmerge

What fields are you using to do the comparison?

If you are doing something like

{ IF { REF EndDate } = { REF StartDate } "equal" "different" }

you need to do something more like

{ IF "{ REF EndDate }" = "{ REF StartDate }" "equal" "different" }

(I don't know why Word needs the quotes in this case) and in any case you
really need to format the dates as YYYYMMDD before you compare them (which
you may be doing) but you can try

{ ={ REF EndDate \@YYYYMMDD }-{REF StartDate \@YYYYMMDD }
\#"'{ REF StartDate \@"M/D" }-{ REF EndDate \@"M/D/YYYY" }';'x';'{ REF
StartDate \@"M/D/YYYY" }'" }

and put something instead of "x" if you need to cover the case where the
start date is after the end date.

If you're using MERGEFIELD fields, some of the above may not apply but you
still need the YYYYMMDD stuff.

Peter Jamieson

walkerh wrote in message ...
This has me puzzled. We have a mailmerge document populated from an
external database via a header and text file. In the letter we compare a
Start Date with an End Date. If they are the same the letter only prints
the Start Date m/d/y. If the End Date is greater than the Start Date, we
format the Start Date for month/day add a dash and format the End Date
month/day/year. We just ran into a case where if the month and day are
the same in the Start Date and the same in the End Date the test fails and
only the Start Date is printed. An example would be SD = 04/04/2007 and
ED = 06/06/2007. changing the SD to 03/03/2007 or 05/05/2007 or the ED in
similiar fashion yields the same failure. A difference in the year
results in the desired behavior. Any thoughts?

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Jules[_2_] Jules[_2_] is offline
external usenet poster
 
Posts: 8
Default if statements with dates in mailmerge

On 6 apr, 20:03, "Peter Jamieson"
wrote:
What fields are you using to do the comparison?

If you are doing something like

{ IF { REF EndDate } = { REF StartDate } "equal" "different" }

you need to do something more like

{ IF "{ REF EndDate }" = "{ REF StartDate }" "equal" "different" }

(I don't know whyWordneeds the quotes in this case) and in any case you
really need to format the dates as YYYYMMDD before you compare them (which
you may be doing) but you can try

{ ={ REF EndDate \@YYYYMMDD }-{REF StartDate \@YYYYMMDD }
\#"'{ REF StartDate \@"M/D" }-{ REF EndDate \@"M/D/YYYY" }';'x';'{ REF
StartDate \@"M/D/YYYY" }'" }

and put something instead of "x" if you need to cover the case where the
start date is after the end date.

If you're using MERGEFIELD fields, some of the above may not apply but you
still need the YYYYMMDD stuff.

Peter Jamieson



walkerh wrote in ...
This has me puzzled. We have a mailmerge document populated from an
external database via aheaderand text file. In the letter we compare a
Start Date with an End Date. If they are the same the letter only prints
the Start Date m/d/y. If the End Date is greater than the Start Date, we
format the Start Date for month/day add a dash and format the End Date
month/day/year. We just ran into a case where if the month and day are
the same in the Start Date and the same in the End Date the test fails and
only the Start Date is printed. An example would be SD = 04/04/2007 and
ED = 06/06/2007. changing the SD to 03/03/2007 or 05/05/2007 or the ED in
similiar fashion yields the same failure. A difference in the year
results in the desired behavior. Any thoughts?


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -


it could help you a lot by using a query containing this sort of
inteligence. I think the formula mentioned will work (except the
quotes around a field, I shouldn't use those). But a query is much
more easy to design.
If your external database doesn't allow to make queries, you could
export the data to a Excel or beter Access file.
Good luck

  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
walkerh walkerh is offline
external usenet poster
 
Posts: 2
Default if statements with dates in mailmerge - PeterJamieson

Thank you Peter. That seems to have cleared it up. I think I read somewhere that mail merge treats dates as text so telling it that these are dates makes sense in my ignorant mind. The 03/03/07 or 04/04/07 or 05/05/07 for a start date failing the in the IF when compared to 06/06/07 can be now be something to ponder if/when I ever get so leisure time.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
assistnace with mailmerge dates from excel Woods Mailmerge 2 May 26th 05 06:29 AM
Mailmerge calculated dates from Excel MervynW1954 Mailmerge 3 April 22nd 05 10:58 AM
Word Mailmerge reading UK dates in Access as US dates Curious of Barnet Mailmerge 4 April 18th 05 12:36 AM
Mailmerge Dates Greg Smart Mailmerge 2 March 18th 05 07:27 PM
Mailmerge Dates [email protected] Mailmerge 0 March 18th 05 02:47 PM


All times are GMT +1. The time now is 11:10 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"