How can I use the IF conditional command in a field to test the value of the current date, given by DATE? I’d like to be able to do things like {IF {DATE} = “this value” {TRUEMACRO} {FALSEMACRO}} only I can’t seem to get it to work; the statement always is false. What format, numerical or alpha, can I test DATE against to get a result of true?
Well, I know nothing about Word so I’m just replying because no one else has. The first thing I would do is to check the value of date to make sure it has the content you believe it has. I would also make sure date is of comparable type to this value, e.g. if this value is a string, date should be a string too. I would also try to store the content of date in variable, then test the content of the varible to this value. Am I on to something?
Hmmm…worked for me. Here’s what I did:
-
Create a DATE field in your document.
-
Select the IF field, right click and “Toggle Field Codes”
-
Ensure that the expanded field looks like this:
{ DATE @ “M/d/yyyy” * MERGEFORMAT } -
In a different place, create an IF field as follows:
IF “11/16/2006”=“11/16/2006” “TRUE” “FALSE”
-
Select the IF field, right click and “Toggle Field Codes”
-
Highlight the previously created DATE field and copy it.
-
Paste the copied DATE field into the IF field codes in place of the first “11/16/2006”
-
“Hide Field Codes”, “Update Field” - should read “TRUE”
That worked on my machine (XP with Word Pro 2003).
Damn, in #2 above, it is, of course, the DATE field you’re selecting…
Just a WAG, but have you tried enclosing your date literal in hash marks?
#this value# as opposed to “this value” makes many thing Microsoft interpret the content as a date rather than a string.
Zakalwe, that seems to work. I forgot that you can’t type field brackets {} manually, you have to use Ctrl-F9 or copy an existing field. I’ll see if the autoupdate works tomorrow, and then play around with getting my macros to work. Thanx!
Quick follow up…Did you ever get this worked out?
Works great! Now all I need to do is figure out how to automate what I want the result of the date test to do. I’m trying to create a calendar using the Calendar wizard and then have it do things like highlight the current date or check off the days gone by.