Re: Word Fields for Forms: Determining if Empty



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.


.



Relevant Pages

  • Re: Word Fields for Forms: Determining if Empty
    ... field contains five nonbreaking spaces (the 'empty' condition). ... "Jay Freedman" wrote: ... IsNull has nothing whatever to do with form fields. ...
    (microsoft.public.word.docmanagement)
  • Re: Creating Filename from Form Data
    ... can a similar macro be used to create file names from the files' "properties" ... "Jay Freedman" wrote: ... the form fields -- what you see in the Bookmark box in the Properties ... When I insert it into my Template, I get a blank filename when I ...
    (microsoft.public.word.docmanagement)
  • Re: UNLOCKING FORMS IN WORD 2007
    ... I followed your instructions and added the Developer tab. ... "Jay Freedman" wrote: ... and you'll find the Protect Document button on it. ... form fields that are locked. ...
    (microsoft.public.word.docmanagement)
  • Re: Tab directly to fill in
    ... "Jay Freedman" wrote: ... the user tabs, we need it to skip the question and tab to the fill in ... The reason I ask these things is that form fields, ... then the grey boxes must not be form fields. ...
    (microsoft.public.word.docmanagement)
  • Re: isset(), empty(), $_GET and $_POST problem
    ... >>cleanis simply a function that trims to the specified length and ... >>applies EscapeShellCmd(). ... >>Yet when I fill out those form fields and submit, ... >>the form with my tracing errors stating that those fields are empty. ...
    (comp.lang.php)