How to update automaticly

P

Peter Verhey

Hi there,

I'm kinda new at vba, and have the following probplem.
I have a document where i have to fill in quiet some fields, i want to make
a form to make that fill in automaticly..But my biggest problem is the
following.

On top of the document i fill in a start date, further in de document there
ar several fields that different one week , when i fill in at the top week 1,
the second field must become automaticly week2, week 3 and so on...

Can anyone tell me how i can achieve that?

Thank you very much...

Regards,

PEter
 
G

Greg

Peter,

If I follow you, you want to enter a date (e.g., 19 January 2005) on
the top of one page and on following pages have 26 January 2005, then
02 February 2005. Is this correct?

Here is a method that you could use. Run this macro:
Sub DateSeq()
Dim myDate As Date
Dim seqNum As Long
Dim seqLength As Long
Dim seqInt As Long
Dim upSeq As Long
Dim i As Long
Dim dateFormat As String

Retry:
On Error GoTo Oops
myDate = InputBox("Enter the start date in 1/01/2005 format.", _
"Start On", Date)
On Error GoTo 0
seqLength = InputBox("Enter the sequence length e.g., 14.", _
"Sequence Length", "14")
dateFormat = InputBox("Enter the format for the date display e.g." _
& "dddd, mmm dd yyyy.", "Date Format", "mmmm dd, yyyy")
seqInt = InputBox("Enter the sequence interval in days.", "Interval",
"1")

For seqNum = 1 To seqLength
upSeq = seqNum * seqInt
ActiveDocument.Variables("Var" & seqNum).Value = _
Format(myDate + upSeq - seqInt, dateFormat)
Next
ActiveDocument.Fields.Update
Exit Sub
Oops:
If Err.Number = 13 Then
If myDate = "12:00:00 AM" Then Exit Sub
If MsgBox("Invalid format! Start date must be in 1/31/2005 format",
_
vbRetryCancel, "Alert") = vbRetry Then
Resume Retry
End If
Resume Next
End If
End Sub

For and example, use 12 as the sequence length and 7 as the interval.
This will create 12 docvarialbes storing the sequenced dates.

Place the following field in your document in each place that you want
a sequenced date to appear.

{ DocVariable{ Quote Var{ Seq Date }}

Note all { } pairs are entered with CTRL+F9. Once you enter one field
you can copy and paste to the other locations. Use CTRL+a and F9 to
update and display the field results.

Hope this helps.
 
P

Peter Verhey

Hello Greg,

Thank you for your tip, I'll hope it will work, only when I run it in Word97
I'll get an compile error on de Sub DateSeq() ..

DO you know by any chance what this can be?

Thank you very much.

Peter Verhey
 
G

Greg Maxey

Peter,

The compile errror is probably due to the unfortunate result of pasting
working code in a newsgroup screen that wraps the text differently than it
should be. You will need to try to identify what line in the code is
causing the comipile errror and fix it. Does a line or lines appear in red?
That is the spot that will need work and it is likely due to the line being
broken in the wrong place.
 

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