2nd page w/ header macro?

R

Roxy

I am wondering if my requests listed below are possible for Word 2003. Any
help would be greatly appreciated thank you in advance.

I have a single page, password protected form, for multiple users, that when
entering text may or may not spill over onto a 2nd page. So I want to know is
if it is possible (with a macro maybe?)
1. If the text ends up going on to a 2nd page auto inserting a header only
for the 2nd page.
2. And, be able to pull data from 2 form fields (the name and date) on page
one and insert the text into the header, so the user doesn't have to retype
it again. For example:
John Smith
April 25, 2008
Page 2

Otherwise the entire time the text is limited to one page, the 2nd page and
its header need to ‘hidden’, and not visible or able to print by the user.

Thanks!
 
F

fumei via OfficeKB.com

1. there is no need to auto insert anything after the fact. Use Page Setup
to set (check) Different first page. Now make a second page. Do whatever
you want with its header. Now delete the page. You are back to a single
page, but the second page header persists. If the first page is extended and
a second page is made, the header will already be there.

2. Yes, absolutely. When you make your dummy second page (in order to put a
header in it), use REF fields. Use a REF field that refers to your name
formfield, and another REF field that refers to your date formfield.

So in your header on page 2, it will look like:

{ REF Text1 }
{ REF Text2 }

with Text1 and Text2 being the formfield bookmark names.

Again, once you have set this up you can delete the page. The header
information will remain. This is very important to know about headers (and
footers).

Now, you can use something like this as an OnExit macro for the name (or date.
..or whatever) formfield.

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub

Voila! The header content for page 2 is updated...even if there IS no page 2.
If there becomes a page 2, the header content is there, with the contents of
the formfields. If there is no page 2...who cares, although the header will
STILL be updated. As, again, header content is always there, whether there
is a page for that header, or not.
 
F

fumei via OfficeKB.com

Oh...VERY important. For the REF to work you must make sure your formfields
have Calculate on exit CHECKED.
1. there is no need to auto insert anything after the fact. Use Page Setup
to set (check) Different first page. Now make a second page. Do whatever
you want with its header. Now delete the page. You are back to a single
page, but the second page header persists. If the first page is extended and
a second page is made, the header will already be there.

2. Yes, absolutely. When you make your dummy second page (in order to put a
header in it), use REF fields. Use a REF field that refers to your name
formfield, and another REF field that refers to your date formfield.

So in your header on page 2, it will look like:

{ REF Text1 }
{ REF Text2 }

with Text1 and Text2 being the formfield bookmark names.

Again, once you have set this up you can delete the page. The header
information will remain. This is very important to know about headers (and
footers).

Now, you can use something like this as an OnExit macro for the name (or date.
..or whatever) formfield.

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub

Voila! The header content for page 2 is updated...even if there IS no page 2.
If there becomes a page 2, the header content is there, with the contents of
the formfields. If there is no page 2...who cares, although the header will
STILL be updated. As, again, header content is always there, whether there
is a page for that header, or not.
I am wondering if my requests listed below are possible for Word 2003. Any
help would be greatly appreciated thank you in advance.
[quoted text clipped - 15 lines]
 
R

Roxy

I am walking through the steps to see if I can make this work, but one
question. I already have an on exit command for the form fields I am
referancing and I know I can't have more then one command. So can I add the
Sub UpdatePage2Header() to my command:
Sub Goto_Firstlast()
Selection.GoTo What:=wdGoToBookmark, Name:="Firstlast"
End Sub
So that it does both actions in one? Thanks for your speedy responses it
makes my job so much easier! :)
 
R

Roxy

So I tried this myself and got a "Compile Error: Ambiguous name detected:
UpdatePage2Header", below is what I did for my 2 separate macros inorder to
have 2 functions for my on exit command;

Sub Goto_Firstlast()
Selection.GoTo What:=wdGoToBookmark, Name:="Firstlast"

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub

Sub Goto_Addy()
Selection.GoTo What:=wdGoToBookmark, Name:="Addy"

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub
 
G

Graham Mayor

If the REF field is in the header, checking this box will not help. You need
a macro to update REF fields in a header as indicated in your earlier post.
The following will update the fields including those in the header

Sub UpdateAllFields()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub

If the REF field is only in the body of the document, the macro is not
required as the Calculate on Exit check box will then work to update the
field.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Oh...VERY important. For the REF to work you must make sure your
formfields have Calculate on exit CHECKED.
1. there is no need to auto insert anything after the fact. Use
Page Setup to set (check) Different first page. Now make a second
page. Do whatever you want with its header. Now delete the page.
You are back to a single page, but the second page header persists.
If the first page is extended and a second page is made, the header
will already be there.

2. Yes, absolutely. When you make your dummy second page (in order
to put a header in it), use REF fields. Use a REF field that refers
to your name formfield, and another REF field that refers to your
date formfield.

So in your header on page 2, it will look like:

{ REF Text1 }
{ REF Text2 }

with Text1 and Text2 being the formfield bookmark names.

Again, once you have set this up you can delete the page. The header
information will remain. This is very important to know about
headers (and footers).

Now, you can use something like this as an OnExit macro for the name
(or date. ..or whatever) formfield.

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub

Voila! The header content for page 2 is updated...even if there IS
no page 2. If there becomes a page 2, the header content is there,
with the contents of the formfields. If there is no page 2...who
cares, although the header will STILL be updated. As, again, header
content is always there, whether there is a page for that header, or
not.
I am wondering if my requests listed below are possible for Word
2003. Any help would be greatly appreciated thank you in advance.
[quoted text clipped - 15 lines]
 
F

fumei via OfficeKB.com

Graham is correct, the Calculate on exit will NOT do anything for the header.

The reason you have "ambiguous" is that you have TWO Subs with the same name.
That is what this error usually means.

Yes, you can have multiple instructions in one Sub.
So I tried this myself and got a "Compile Error: Ambiguous name detected:
UpdatePage2Header", below is what I did for my 2 separate macros inorder to
have 2 functions for my on exit command;

Sub Goto_Firstlast()
Selection.GoTo What:=wdGoToBookmark, Name:="Firstlast"

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub

Sub Goto_Addy()
Selection.GoTo What:=wdGoToBookmark, Name:="Addy"

Sub UpdatePage2Header()

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
.Range.Fields.Update

End Sub
I am walking through the steps to see if I can make this work, but one
question. I already have an on exit command for the form fields I am
[quoted text clipped - 62 lines]
 
G

Graham Mayor

I missed your message on the 25th, however what you have here are four subs
with only two end subs; and two of the subs have the same name and fulfil
the same function. It is not clear what these macros are supposed to do
or why you need to do some of it twice.
If you want to update REF fields in the header/footers use the update macro
I posted earlier on exit from the field that provides the data for the REF
field. If you have more than one REF field then run it on exit from the last
relevant field. If you want to add code to take you from that field to a
specific form field then add it to the end of the update macro before the
End Sub eg

Selection.GoTo What:=wdGoToBookmark, Name:="Firstlast"
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Roxy

Hello Fumei,
I tried Graham's code and neither of my {REF} updated in my header when I
tried. So I am back to trying to combine to codes into one so I can use one
exit macro but I got a "Compile Error: Expected End Sub" when I tried this.
The multiple codes that are the same but with differant bookmarknames are to
direct the users tabing order. I just need to combine one GOTO and your
UPDATEPAGE2HEADER, if you could please help...... (I changed the macro name
to make the 2 differ so I wouldn't get the "Ambigious name error")

Sub Goto_Addy()
Selection.GoTo What:=wdGoToBookmark, Name:="Addy"
Sub UpdatePageHeader()
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
..Range.Fields.Update
End Sub
Sub Goto_Citystate()
Selection.GoTo What:=wdGoToBookmark, Name:="Citystate"
End Sub
Sub Goto_ICCISID()
Selection.GoTo What:=wdGoToBookmark, Name:="ICCISID"
End Sub
Sub Goto_CWname()
Selection.GoTo What:=wdGoToBookmark, Name:="CWname"
End Sub
Sub Goto_Telenumber()
Selection.GoTo What:=wdGoToBookmark, Name:="Telenumber"
End Sub
Sub Goto_Date2()
Selection.GoTo What:=wdGoToBookmark, Name:="Date2"
End Sub

Sub UpdatePage2Header()
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
..Range.Fields.Update

End Sub
 
G

Graham Mayor

The macro I posted earlier should update your headers, however your problem
here is

Sub Goto_Addy()
Selection.GoTo What:=wdGoToBookmark, Name:="Addy"
Sub UpdatePageHeader()
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
..Range.Fields.Update
End Sub


The missing End Sub is before Sub UpdatePageHeader()
If you want to combine the two macros then

Sub Goto_Addy()
Selection.GoTo What:=wdGoToBookmark, Name:="Addy"
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) _
..Range.Fields.Update
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Roxy

Thank you Graham. I think I am doing something wrong still though since I
can't get either of you or Fumei's suggestions to work. I think it has to do
with my REF field in my header on page 2.
I typed it in just like the following:
{REF Date1}
{REF Firstlastname}

Since I am still very new to VBE and macros I hope I didn't take it too
literal and was supposed to do/make some other 'REF field' instead of type in
the symbols and letters. I hope you can help me to understand this better.
Thanks again!
~Roxy
 
G

Graham Mayor

You can't just type in fields you must use CTRL+F9 for the field boundaries
{}.
Date1 and Firstlastname must refer to the bookmark names (form fields) in
the document.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Roxy

That was it! Thank you so much, now everything works perfectly. I guess the
only way to learn is to mess up a few times and keep asking questions. ;)

Thank you very very much for all your continued help!

~Roxy in Alaska
 
G

Graham Mayor

You are welcome :)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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