If statement with dates

W

word

I have tried various iterations and have not been able to find a
solution.

We use a program to insert bookmarks into word from an SQL server. One
of the fields is a date and it is either a date or an empty field. I
am trying to get the date to display if there is one and an "N/A" if
there is not.

I have tried the following

{ =if imported_date <> 0 imported_date N/A}

I've tried it with { } around the bookmarks and " " and all sorts of
switches. I even tried converting the date to a different format
yyyyMMdd and comparing it.

Please somebody help.

Thanks,

Ryan

(e-mail address removed)
 
J

Jay Freedman

Hi Ryan,

What does the program insert if the date in the database is empty? Is it an
empty bookmark? If so, the field you need is this:

{ IF {imported_date} <> "" {imported_date} "N/A"}

To get the braces around the bookmark name nested inside the IF field, you
MUST use Ctrl+F9 -- you can't just type the braces on the keyboard.

What this says is:

- Evaluate the content of the bookmark named imported_date.
- If that content is not an empty string (represented by ""), then show the
content of the bookmark.
- If that content is an empty string, then show the string "N/A".

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
W

word

Thanks very much, but it does not work as you've typed it. The
bookmark is blank, but I get a syntax error still. It seems like it
should work based on everything I have read.

Here is what I have typed in (using Ctrl-F9 when needed)

{ if {Contract Date} <> "" {Contract Date} "N/A" }

It gives me an undefined bookmark error. So I took out the braces and
it doesn't give me an error, but is blank. The bookmark is empty when
I see the contents with the brackets [].

I would be happy to pay for consulting services if someone would tackle
this issue for me.
 
W

word

Well, the database program allows us to insert bookmarks into the word
documents using a customized bookmark assistant program. I don't know
technically how they do it, just that it works like that. We go
through a template document and place these bookmarks where we have
dynamic information that needs to be populated. I've used bookmarks
within the word tables for calculations, so I don't think it has
anything to do with a space in the name.

I'm as confused about this as anybody, seems like half the time my
calcs work, half the time they don't.
 
T

Tony Jollans

I suspect it's looking for a bookmark called "Contract" - and not finding
one.

Can you look at your bookmarks under Insert > Bookmarks and see what there
is?
 
W

word

The bookmark is actually kf50e52e783c6487a96 but is actually being
inserted as Contract Date so that I know what it is. Once again, I
don't know how all of this works with the SQL server, but a program
called boomark assistant allows me to place these named bookmarks
throughout the document.

The search continues and I appreciate all the input.

Ryan
 
T

Tony Jollans

If you're going to manually edit the results of another program you're going
to have to use whatever it generates. In this case it looks like you will
need ..

{ if {kf50e52e783c6487a96} <> "" {kf50e52e783c6487a96} "N/A" }

This may give you some maintainability problems - depending on how your
bookmark assistant works - I don't know.
 

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