Document Date

C

Chris Stammers

Hello,

I am using Word 2002 and I have a problem with the { DATE } field. Our data
source is an AS400 platform that doesn't contain the date a record was
created therefore I have been using the following: { DATE \@ "d" \*ordinal }
{ DATE \@ "MMMM yyyy }. This is OK however we have an automatic scanning
facility which is used to recall letters if a customer wants a copy. This has
to have the original date the letter was produced and unfortunately, the
above field will always show the current days date. Is there a field switch I
can use to hardcode the date the letters are generated through the merge? I
have tried CREATEDATE and SAVEDATE; CREATEDATE only ever returns the date the
document was created (obviously, perhaps). SAVEDATE would be prone to
changing if something in the document changes after it has been opened. Any
suggestions?

Thanks,
Chris
 
D

Doug Robbins - Word MVP

I would have thought that the date on which the document was created as
results from the use of the CREATEDATE field would be the date that you want
on the letter. If for some reason that is not, the you would need to unlink
the date field, by selecting it (or the whole document and using
Ctrl=Shift+F9. That of course could be done by the use of some VBA code.

--
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

If you have a merge document with DATE fields, a merge to a new document
will retain the Date field format and always show the system date (the
problem you currently have).
If you have a merge document with CREATEDATE fields a merge to a new
document will always show the date in the merge document, which is what you
are finding.

To get around this you have three choices.

1. Use SaveAs to save the merge document with the same filename then update
the CREATEDATE fields *before* merging

Sub UpdateCreateDate()
Dim sfName As String
Dim strCodes As String
Dim iFld As Integer
sfName = ActiveDocument.FullName
ActiveDocument.SaveAs FileName:=sfName, FileFormat:=wdFormatDocument
Selection.HomeKey
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldCreateDate Then
.Update
End If
End With
Next iFld
End Sub

OR

2. Keep the DATE fields and run a macro to replace the DATE fields with
CREATEDATE fields in the new document

Sub ChangeFieldContent()
Dim strCodes As String
Dim iFld As Integer
Dim strFind As String
Dim strRepl As String
Selection.HomeKey
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldDate Then
.Code.Text = Replace(UCase(.Code.Text), _
"DATE", "CREATEDATE")
End If
End With
Next iFld
End Sub

OR
3 Unlink the DATE fields in the merged document

Sub UnlinkDateField()
Dim strCodes As String
Dim iFld As Integer
Selection.HomeKey
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldDate Then
.Unlink
End If
End With
Next iFld
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter Jamieson

CREATEDATE may do it if you have the right starting point (probably a
template rather than a document).

But if not, when you get data from the AS400, can you specify a SQL Query
that lists a function like today() as one of the fields, in addition to the
fields you're getting from the data source? (I don't know what facilities
are on offer in AS400-land)

If not, you can probably use the technique described in

http://tips.pjmsn.me.uk/t0004.htm

to insert today's date (e.g. using the date() function) and destroy the
field during the merge.

Ideally you would be able to use just one DATABASE field to return the value
formatted exactly as you want it, but since there's a problem whereby Word
now adds a paragraph mark to the result of a DATABASE field, you'll probably
need either
a. two copies of the same DATABASE field (so you can apply the two separate
formats you are using at the moment) or
b.
{ SET today { DATABASE ... } }
then
{ REF today \@ "d" \*ordinal } { REF today \@ "MMMM yyyy }

etc.

Haven't tried that specific approach, and the DATABASE field won't work
inside tables.
 

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