Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Automatically enter the text from a text field in headers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nevets - 17 Dec 2007 16:09 GMT
Creating a form, with two text fields on page 1.  The text fields are
bookmarked as EventName and EventDate.  I would like to have the Event Name
and Date automatically appear on the second and subsequent page headers.  
I've done this previously, but not within a header.  I put the cursor in the
header where I wanted the EventName text to appear, hit Control + F9, then
typed EventName in the field.  After hitting toggle field codes, I protected
the form and tested it.  Nothing appears in the headers after I enter the
name in the EventName field and tab out.  If I do the same thing somewhere
else in the document, it works.  How do I get this to work in a header?
David Sisson - 17 Dec 2007 19:41 GMT
Inside header, Insert ->Field ->Ref, Select bookmark name

File -> Page setup -> Layout tab, check Different first page.
Nevets - 17 Dec 2007 20:19 GMT
What you suggested seems to make sense, but when I tried it, nothing happens.
I hit insert > Field > Ref, and among the list of bookmarks, selected
EventName and EventDate, which are the two bookmarks names of the first two
text fields in the document.  Protected the form then saved it, then entered
text in the two fields.  Nothing gets added in the header.  If I hit Alt+F9,
I see { REF EventName } and { REF EventDate } where I expect to see the text,
but no actual text gets added when I tab out of either of the text fields.
For the sake of argument, I tried the same thing in a footer, and in the
body of the document, with no luck in either location.  Also tried removing
everything else from a footer, but again, no luck.

> Inside header, Insert ->Field ->Ref, Select bookmark name
>
> File -> Page setup -> Layout tab, check Different first page.
Greg Maxey - 17 Dec 2007 20:32 GMT
The problem is that your field is not being update due to its location in a
header or footer.  It you unprotect the form and go to the header, CTRL+a ,
F9 the field will update.

You can also see the update by opening and closing PrintPreview.

I would attach and onExit macro to the text field that runs:

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> What you suggested seems to make sense, but when I tried it, nothing
> happens. I hit insert > Field > Ref, and among the list of bookmarks,
[quoted text clipped - 11 lines]
>>
>> File -> Page setup -> Layout tab, check Different first page.
Nevets - 17 Dec 2007 21:28 GMT
How do I attach the on-exit macro.  There is an option to add a macro on exit
from the text fields, but I don't know how to create/save your macro so that
it is available as an option in the drop-down.

> The problem is that your field is not being update due to its location in a
> header or footer.  It you unprotect the form and go to the header, CTRL+a ,
[quoted text clipped - 22 lines]
> >>
> >> File -> Page setup -> Layout tab, check Different first page.
Greg Maxey - 17 Dec 2007 21:37 GMT
You need to put this macro in the document project module:

Sub MyOnExit()
With ActiveDocument
 .PrintPreview
 .ClosePrintPreview
End With
End Sub

See: http://www.gmayor.com/installing_macro.htm

The with the form unprotected, double click the textfield and set "OnExit"
to run On Exit from the field.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> How do I attach the on-exit macro.  There is an option to add a macro
> on exit from the text fields, but I don't know how to create/save
[quoted text clipped - 33 lines]
>>>>
>>>> File -> Page setup -> Layout tab, check Different first page.
Nevets - 18 Dec 2007 19:24 GMT
Figured out how to have your suggested macro run on exit from the text field,
but still having a small problem.  I want the footer text to be small font
(8).  I "Ctrl+a" within the footer, then choose 8 for the font size.  When I
tab out of the EventName field, the text is entered, with the first word font
size 8, but the rest of the Event Name is size 12.

Any ideas?

> The problem is that your field is not being update due to its location in a
> header or footer.  It you unprotect the form and go to the header, CTRL+a ,
[quoted text clipped - 22 lines]
> >>
> >> File -> Page setup -> Layout tab, check Different first page.
Greg Maxey - 18 Dec 2007 21:31 GMT
I didn't test this but it should work.. Put your field in the footer like
this  { REF EventName \* CharFormat }  then select the "R" and format it as
8 point.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Figured out how to have your suggested macro run on exit from the text
> field,
[quoted text clipped - 35 lines]
>> >>
>> >> File -> Page setup -> Layout tab, check Different first page.
Nevets - 18 Dec 2007 21:53 GMT
In the footer field, it says the following:  {REF  EventName  \*
MERGEFORMAT}, not CharFormat, so I'm not sure if your suggestion will work or
not.
In any event, I tried something else while waiting for your reply.  I
selected all the text in the footer, made it 8 point, then updated the footer
style to match the selected text.  This seems to have worked, in that when I
create a new form from the template and enter the EventName and EventDate
text, it comes out as 8 point font in the footers.  I think I'll leave well
enough alone.

> I didn't test this but it should work.. Put your field in the footer like
> this  { REF EventName \* CharFormat }  then select the "R" and format it as
[quoted text clipped - 39 lines]
> >> >>
> >> >> File -> Page setup -> Layout tab, check Different first page.
Greg Maxey - 18 Dec 2007 22:13 GMT
If it works don't fix it, but you could have changed \* MergeFormat to \*
CharFormat and did the rest and it should have worked.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> In the footer field, it says the following:  {REF  EventName  \*
> MERGEFORMAT}, not CharFormat, so I'm not sure if your suggestion will work
[quoted text clipped - 60 lines]
>> >> >>
>> >> >> File -> Page setup -> Layout tab, check Different first page.
eastlaketech - 19 Dec 2007 20:52 GMT
The macros & formatting works great on my computer.  When I send the form to
someone else, it doesn't work.  Any help would be appreciated.

> I didn't test this but it should work.. Put your field in the footer like
> this  { REF EventName \* CharFormat }  then select the "R" and format it as
[quoted text clipped - 39 lines]
> >> >>
> >> >> File -> Page setup -> Layout tab, check Different first page.
fumei - 17 Dec 2007 20:33 GMT
>Inside header, Insert ->Field ->Ref, Select bookmark name
>
>File -> Page setup -> Layout tab, check Different first page.

That does not work with 2002.  I am not sure if it does with 2003.  Using Ctl-
F9 and formfield name, or Insert > Field > Ref + bookmark name, in the header
will not update.  Even with Calculate on exit checked for the formfield.

It will work, however, with other places in the MainStory.  And that is the
issue.

You could add a wee OnExit macro to your formfield.

Sub UpdateHeaders()
Dim oHF As HeaderFooter
For Each oHF In ActiveDocument.Sections(1).Headers
  oHF.Range.Fields.Update
Next
End Sub
David Sisson - 17 Dec 2007 20:37 GMT
> >Inside header, Insert ->Field ->Ref, Select bookmark name
>
> >File -> Page setup -> Layout tab, check Different first page.
>
> That does not work with 2002.  I am not sure if it does with 2003.  Using Ctl-

Cursed version differences!

I am using 2003.

Thanks for the tip!
Greg Maxey - 17 Dec 2007 21:09 GMT
fumei,

Concede that in this instance that would probably work, but as a point of
illustration put a shape in your header, right click the shape and select
add text and then put the field the shape.

You will see that, for reasons I don't understand, shapes contained in
headers and footers are not processed with the header or footer storyrange
or with the normal shape range.  They have to be processed as a unique
collection.

See:  http://gregmaxey.mvps.org/Field_Macros.htm

For this instance this code will work if run on exit:

With ActiveDocument
 .PrintPreview
 .ClosePrintPreview
End With

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

>> Inside header, Insert ->Field ->Ref, Select bookmark name
>>
[quoted text clipped - 16 lines]
> Next
> End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.