Change form field font in protected form

N

notmeg

Hello,
I have a macro that is designed to change the font size and color of
the form fields in a protected form. It basically unprotects the form,
applies the changes, then reprotects. The problem is that sometimes,
when the user types more into a form field after making the change, the
new text is in the default font size/color. The behavior is really
weird, it seems to only happen if you start typing after the first
carriage return in a field, and even then it's intermittent. I've tried
making the change using a style instead, but that seemed to have no
effect. Here's the code I'm using to make the font color/size change:

For Each oSection In oDoc.Sections
For Each FmFld In oSection.Range.FormFields
If FmFld.Type = wdFieldFormTextInput Then
If strFontSize <> "" Then
FmFld.Range.Font.Size = strFontSize
End If

FmFld.Range.Font.Color = strColor
End If
Next
Next

Any ideas why this could be happening?

Thanks in advance!
 
J

Jezebel

You're setting the size not for the field itself, but for its range. If the
user appends additional text, the appended matter is outside that range.
 
N

notmeg

One other thing: on one set of forms, this strange behavior does not
seem to happen. I can make the font change and start typing in the
field and it looks like the new color/size I selected. A different set
of forms (same macro) has the weird behavior and it doesn't happen all
the time...only after the first carriage return (from what I can tell).
 
J

Jezebel

Rather than try to fix the macro, why are you doing this at all? Why not
just set up the form as you want it, with the fields formatted as you need
them?
 
J

Jezebel

Just say no. They want to be 'able' to do this, but they won't actually do
it. Ignore the request.

If you must: define a formfield style, apply it to the formfields, and let
them redefine that style.
 
N

notmeg

Actually, they will do it, this I know for sure. But that's really not
the point.

In a protected form, the user cannot modify styles. So that won't work.
I guess I wonder why my code works flawlessly for some forms and not
for others. If it is as you say, then I would expect the same weirdness
 
M

mae

Apparently you prefer to spend your days spreading bitterness and negativity.
Why don't you stick to coding quietly in a cube, rather than trying to
interact with people? Everyone has their weaknesses and their strengths.
I'm sure you're a very good programmer, but obviously interpersonal
communication ("people skills") aren't your forte, so why do you force it?
 
C

Charles Kenyon

Let's make sure I understand your task.

You want users to be able to change the formatting for all text form fields
in a protected document? Not one individual form field, but all of them?

By the way, how are you getting strColor and strFontSize?

Version of Word?

Any chance that there is a difference is the section setup between the forms
where it works for you and those where it does not? Protected/unprotected
sections?

I agree with Jezebel that this is not something you should be doing, but I'm
bored and am willing to play a bit with it to try to learn something. I'm
not a programmer.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
N

notmeg

Charles,
Yes, they want to be able to change the formatting for all the text
form fields in the protected document.

strColor and strFontSize come from a userform.

Version of Word: let's go with 2003.

Both sets are completely protected...I'm trying to figure out if there
is some difference between them but I haven't found it yet. I've run
into things like this in Word before and sometimes to "fix" it you have
to do strange things and it just works. So far nothing has.

Thanks!
 
J

Jean-Guy Marcil

notmeg was telling us:
notmeg nous racontait que :
Charles,
Yes, they want to be able to change the formatting for all the text
form fields in the protected document.

strColor and strFontSize come from a userform.

Version of Word: let's go with 2003.

Both sets are completely protected...I'm trying to figure out if there
is some difference between them but I haven't found it yet. I've run
into things like this in Word before and sometimes to "fix" it you
have to do strange things and it just works. So far nothing has.

I tested your code as is (or almost!) - (Word 2003 SP2) :

'_______________________________________
Dim oSections As Section
Dim oDoc As Document
Dim fmFld As FormField
Dim strFontSize As Long
Const myBlue As Double = 16711680
Const myLightOrange As Double = 39423

strFontSize = 15

Set oDoc = ActiveDocument

oDoc.Unprotect

For Each oSection In oDoc.Sections

For Each fmFld In oSection.Range.FormFields
If fmFld.Type = wdFieldFormTextInput Then
If strFontSize <> 0 Then
fmFld.Range.Font.Size = strFontSize
End If

fmFld.Range.Font.Color = myBlue
End If
Next
Next

oDoc.Protect wdAllowOnlyFormFields, True
'_______________________________________

and I never saw the problems you did. So, I do not think it is the code per
se that is the trouble.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Charles Kenyon

Sorry, given Jean-Guy's diagnosis, I don't think I'll be able to help.

Things to look at when you get formatting anomolies include direct
formatting and style formatting. Note that his color selections were
constants rather than strings.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
N

notmeg

Thanks everyone.

I think you are correct. I noticed on that on the forms that are
exhibiting the problem, not all the fields are doing it. Only the ones
that have more complex formatting (like numbered lists and such) are
doing it. So right now, my solution would be to rework those forms and
see if it helps.

Thanks again!
 

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