Re: Word Fields for Forms: Determining if Empty
- From: Access101 <Access101@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Mar 2007 11:34:03 -0700
Jay,
Thanks for all your help. Good advice on the NoReset too.
I'm unable to get the 0 lenth, so I've concocted an ugly workaround for now:
If Len(ActiveDocument.Fields(f).Result) = 5 Then
cCount = 0
For c = 1 To 5
If Asc(Mid(ActiveDocument.Fields(f).Result, c, 1)) = 32
Then
cCount = cCount + 1
End If
Next c
End If
If cCount = 5 Then
Else
myString = myString & Chr(9) & Selection
End If
"Jay Freedman" wrote:
Yes, I do get a length of 0, not 5, from that expression when the.
field contains five nonbreaking spaces (the 'empty' condition).
The code I'd recommend for unprotecting the document is this (of
course, supply the correct password, or omit the whole Password
parameter if the form hasn't been given a password):
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="sdfgfgh"
End If
The reason for the If statement is that trying to unprotect a document
that's already unprotected causes an error.
To reprotect the document at the end, use this:
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:="sdfgfgh"
The NoReset parameter prevents the clearing of the field results.
Again, set the password correctly or omit the parameter (and the comma
that precedes it).
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Tue, 27 Mar 2007 19:02:55 -0700, Access101
<Access101@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Jay,
Thanks for your suggestion. Can you plug your code into Word and give it a
test (unless you've used this before and seen it work).
Because I'ms till getting a Len of 5:
msgbox Len(Trim(ActiveDocument.Fields(f).Result))
I'd also be interested in being able to unlock the form at the beginning of
the code, and then lock it back up at the end, but am having trouble making
this work.
"Jay Freedman" wrote:
On Fri, 23 Mar 2007 17:19:03 -0700, Access101
<Access101@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Is there a way to find out if a field has data in it, IsNull?
If IsNull(ActiveDocument.Fields(f)) then
If I use the Len(), I get 5 as the standard, when it's empty
IsNull has nothing whatever to do with form fields. You've already
found most of the correct answer: An 'empty' text form field contains
five nonbreaking spaces (unless you set the default value to something
else in the field's Properties dialog). Probably the best way to test
the field is
If Len(Trim(ActiveDocument.Fields(f).Result)) = 0 Then
The Trim function removes all leading and trailing blanks, so its
value for an 'empty' field will be a zero-length string.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
- References:
- Re: Word Fields for Forms: Determining if Empty
- From: Jay Freedman
- Re: Word Fields for Forms: Determining if Empty
- From: Jay Freedman
- Re: Word Fields for Forms: Determining if Empty
- Prev by Date: Re: Mass change of Margins
- Next by Date: Re: In-document hyperlinks
- Previous by thread: Re: Word Fields for Forms: Determining if Empty
- Next by thread: Re: Flesch Kincaid Index?
- Index(es):
Relevant Pages
|