FormFields("Text1").Result - Exit Macro Problem

R

RPJ

A multi-page Word form uses an Exit Macro in formfield near the bottom of the
document to vet data etc.

If this macro requires a value from the contents of a formfield which is not
currently on display Word will "jump" to display that part of the document
containing the referenced field despite the focus of the document (i.e. the
next selected field) being elsewhere.

Any further keyboard activity will cause Word to "jump" back to displaying
the now in-focus field.

Suspending ScreenUpdating whilst reading the distant FormField and then
reinstating ScreenUpdating has no effect on this disorientating and
irritating phenomenon.

Is it possible to "read" the contents of a document's formfield without Word
changing what is on display?

All help very gratefully accepted.

Rgds,

RPJ
 
G

Graham Mayor

What do you want to do with the value from the form field, with your macro,
having obtained it?
If you want to validate form fields - take a peek at
http://www.gmayor.com/formfieldmacros.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


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

RPJ

GRAHAM,

Your response shows a simple but effective validation technique.

However, my problem concerns the way that Word suddenly changes how the
document is displayed when the Exit Macro on one FormField includes a
reference (e.g. FieldStr1 = .FormFields("Text1").Result ) to another
FormField elswhere within the document. How can I stop the document "jumping
about"?

Still looking for help,

RPJ
 
G

Graham Mayor

It shouldn't jump anywhere but the following field when you tab out of of a
field, unless your exit macro selects a different location. Without seeing
your code it is difficult to advise. FWIW the line you have quoted should
not do anything but record the content of Text1 if the variable FieldStr1

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


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

RPJ

Graham,

I really appreciate your perseverance with this. . . . .

The "code" in the Exit Macro is very simple - see below.

One factor I omitted in my original description is that the document is
displayed in Print Layout (but I have no idea if this is a factor).

Imagine a locked multi-page Word 2003 form. The very first FormField at the
top of the document is called "Text1". You have been travelling down the
form / document and are about to tab out of the penultimate field - when its
Exit Macro (EM23) is called.

The Exit Macro is as follows:

Sub EM23()
With ActiveDocument
Msgbox(.FormFields("Text1").Result)
End With
End Sub

The Word window suddenly shows the area of the document containing the
"Text1" FormField - but the cursor is no longer visible. However, when you
touch the right arrow-key the Word window suddenly resumes its view of the
fields where you were in before.

This is surprising, disorientating, irritating, etc.

Is there a way to prevent Word from doing it?

Still hanging in there . . . . . . .

RPJ
 
D

Doug Robbins - Word MVP on news.microsoft.com

If you use

With ActiveDocument
MsgBox .FormFields("Text1").Range.Text
End With

The data entered into the formfield will be display without the focus
changing.

--
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, originally posted via msnews.microsoft.com
 
R

RPJ

Brilliant! It works a treat.

Many thanks.

RPJ

Doug Robbins - Word MVP on news.microsof said:
If you use

With ActiveDocument
MsgBox .FormFields("Text1").Range.Text
End With

The data entered into the formfield will be display without the focus
changing.

--
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, originally posted via msnews.microsoft.com
 

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