If FormFields Text is empty

U

Ulf Nilsson

Hi,
How do I determine if a FormFields Text is empty? This does not work:

With ActiveDocument.Bookmarks("Text1").Select
If Selection.Text <> "" then
MsgBox "Not Empty"
Else
MsgBox "Empty"
End If

Background:
I fill the document with facts from a file (Text.ini) and want to hide
FormFields Text that are empty. I know how to hide FormFields Text but not to
determine if the FormFields Text is empty.

// Ulf
 
G

Graham Mayor

See also http://www.gmayor.com/formfieldmacros.htm for an alternative
method of validating field entry, however to answer your immediate question

If ActiveDocument.FormFields("Text1").Result <> "" Then
MsgBox "Not Empty"
Else
MsgBox "Empty"
End If


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Gordon Bentley-Mix on news.microsoft.com

You may also wish to consider whether a form field that contains nothing but
blank spaces is "empty" as well. If it is then:

If Trim(ActiveDocument.FormFields("Text1").Result) <> "" Then
MsgBox "Not Empty"
Else
MsgBox "Empty"
End If

In addition, there is a (*very* slight) gain in efficiency in using the Len
function rather than a string comparison; e.g.:

If Len(Trim(ActiveDocument.FormFields("Text1").Result)) > 0 Then
MsgBox "Not Empty"
Else
MsgBox "Empty"
End If
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 

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