Compare two fields from a data source before inserting text

H

harg7769

Is it possible to compare two fields in a data source, and based on
that comparison, enter a specific block of text. I realise that it has
to do with the IF THEN ELSE merge field but I can't seem to get it to
work correctly.

The two fields in the data source are InstDate and Current_Date. If
InstDate >= Current_Date then I want to say ... but if InstDate <
CurrentDate, then I want to say something else.

I went into the Insert Word Field and selected If Then Else. I then
chose the InstDate in the Field Name Box, changed the comparison box
to >= then in Compare To, I have tried typing Current_Date,
{MERGEFIELD Current_Date},
{MERGEFIELD "Current_Date"} but I haven't been able to get it right.

Can I type the code directly instead of using the drop down boxes?

Andrew H
 
G

Greg

Andrew,

Yes, Change the "A" "B" to your field names and this
should work:

{ IF {MERGEFIELD A} >= "{MERGEFIELD B}" "YES" "NO" }
Where {} is entered with insert field brackets CTRL+F9
and "YES" "NO" is substituted for your desired text block.

Delete wha....m to reply in e-mail.
 
H

harg7769

Sorry to follow this one up so late, but I'm still trying to get it to
work. At the moment the code I have is as follows:

{IF {InstDate} >= {CDate} "will soon be out of warranty." "is now out
of warranty"}

The problem is that everything is coming through as TRUE, and so
ievery record shows "will soon be out of warranty", which is obviously
not rue, as it shows the expiry date (InstDate) at the top of the
page. CDate is just today's date.

Does Word have a problem with dates in general? I know that if I try
and use an Excel spreadsheet as a data source and it has dates in it,
then Word will put my dates into the American format, even although I
have them in the British format.

This time I have been using a raw text file as the data source, and
the dates are showing correctly but I get the impression that Word is
struggling to compare dates, and that I maybe have to do something to
the dates first to get it to compare correctly.

ANy suggestions anyone?

Andrew Hargreaves
 
C

Cindy M -WordMVP-

Does Word have a problem with dates in general?Yes, definitely.

You may want to try including a date-picture switch in the fields (and
leave the term Mergefield in them!) to see if that helps at all. I might
try \@ "yyyy-mm-dd" to achieve the best comparison.
Sorry to follow this one up so late, but I'm still trying to get it to
work. At the moment the code I have is as follows:

{IF {InstDate} >= {CDate} "will soon be out of warranty." "is now out
of warranty"}

The problem is that everything is coming through as TRUE, and so
ievery record shows "will soon be out of warranty", which is obviously
not rue, as it shows the expiry date (InstDate) at the top of the
page. CDate is just today's date.

Does Word have a problem with dates in general? I know that if I try
and use an Excel spreadsheet as a data source and it has dates in it,
then Word will put my dates into the American format, even although I
have them in the British format.

This time I have been using a raw text file as the data source, and
the dates are showing correctly but I get the impression that Word is
struggling to compare dates, and that I maybe have to do something to
the dates first to get it to compare correctly.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
M

Marty

Andrew,

Did you receive a workable answer to your query "caomparing two dates" ?? If you did can you please share the answer, as i am having to copare two dates and find the same problems that you faced.

Marty
 

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