Using IF...Then when merging dates from Access to Word

E

Ecofreak

I am trying to create a document that brings a date from Access to Word.
Problem is, I want all dates prior to a set date to register as one date and
all others to register as the date in the database. I created the following
expression in Word
{IF{MERGEFIELD Anniversary}>6/21/2004 {Mergefield Anniversary\@"MMMM
d,yyyy"} "June 21, 2004"}. But the only output I get, regardless of the
Anniversary date is the Anniversary date. Is there a way to write this
expression that will give me the answer I want? (Either in Word or in an
Access Query?) BTW using Office 2000.
 
P

Peter Jamieson

The comparison operators >, < and so on do not work with dates - to get
numbers that can be compared in a useful way, try

{ IF{MERGEFIELD Anniversary \@YYYYMMDD } > 20042106
"{Mergefield Anniversary \@"MMMM d,yyyy"}" "June 21, 2004"}

Also, please note that there should be spaces around the ">", it's
advisable to put quotes round both results (as shown) and all the {} need to
be the special field codes you can insert using cttrl-F9

Peter Jamieson
 
D

Doug Robbins

It's also better to do the manipulation with a query in Access. After all,
it is a database and Word is a word processor.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

Ecofreak

I tried creating an IIF expression in a query:
IIF([Anniversary] > 06/21/2004, [Anniversary], "June 21, 2004") but all I
get is an error message. I'm not at work right now, so I can't tell you
precisely what it says. Something to the effect that it doesn't recognize it
as an If statement.

How does one go about creating an expression to do what I want?
 
D

Doug Robbins

The date needs to be enclosed inside ##

IIF([Anniversary] > #06/21/2004#, [Anniversary], "June 21, 2004")

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Ecofreak said:
I tried creating an IIF expression in a query:
IIF([Anniversary] > 06/21/2004, [Anniversary], "June 21, 2004") but all I
get is an error message. I'm not at work right now, so I can't tell you
precisely what it says. Something to the effect that it doesn't recognize
it
as an If statement.

How does one go about creating an expression to do what I want?

Doug Robbins said:
It's also better to do the manipulation with a query in Access. After
all,
it is a database and Word is a word processor.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

You must use the correct syntax - see Peter's example. The field boundaries
are inserted with CTRL+F9
See also http://www.gmayor.com/formatting_word_fields.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
I tried creating an IIF expression in a query:
IIF([Anniversary] > 06/21/2004, [Anniversary], "June 21, 2004") but
all I get is an error message. I'm not at work right now, so I can't
tell you precisely what it says. Something to the effect that it
doesn't recognize it as an If statement.

How does one go about creating an expression to do what I want?

Doug Robbins said:
It's also better to do the manipulation with a query in Access.
After all, it is a database and Word is a word processor.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

Ecofreak

Thanks to both Doug and Peter. I was able to create the statement I needed
in both Word and Access. This will definitely prove helpful in the future.
 

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