Help for a Newbie, Please

M

MarieP

Hello,

I have created a form and would like to include a macro that will check if
two particular fields have been filled in at the time the user exits the
document (as opposed to checking upon exiting the fields). The fields have
the bookmark names "Text1" and "Text2." If neither of the fields are
answered, I would like one of three possible message boxes to appear, each
with a different question, depending on the circumstances: (1) "The field
Text1 has not been addressed. Continue exiting?" or (2) "The field Text2 has
not been addressed. Continue exiting?" or (3) Neither fields Text1 nor Text2
have been addressed. Continue exiting?" I am VERY new to writing VBA macros.
In the last two days I have read the questions and answers addressed in the
MS Community and the "how to's" on many websites, including the ones
recommeded here. I've picked up some knowledge, but apparently not enough. I
know this is a tall order, but if anyone can suggest how to write a macro for
this I would be most appreciative!
 
S

Shauna Kelly

Hi Marie

First, I strongly recommend that you give your fields' bookmarks nicer
names. Unless your form is a linguistic survey, "Text1" and "Text2" aren't
good names. Names like "FamilyName" or "ReportSubject" or "DateOfBirth" or
"EmployeeNumber" are better names. Or, you might use a prefix to indicate
that these are bookmark names (so your VBA code will be easier to read). So
you might use, for example "bmDepartment" or "bmManagerName". To re-name
your fields, right-click the field, choose Properties and give them good
names. But for this purpose, I'll refer to them as "Text1" and "Text2".

Second, if you haven't already done so, read the following article and the
articles by Dian Chapman that link from it:
How to create a template that makes it easy for users to "fill in the
blanks", without doing any programming
http://www.word.mvps.org/FAQs/Customization/FillinTheBlanks.htm

The next step will be to write the code that checks whether your bookmarks
contain any text. Here's something to get you going:

If ActiveDocument.FormFields("Text1").Result =
ActiveDocument.FormFields("Text1").TextInput.Default Then
MsgBox "Text1 is empty"
End If


Finally, you need to work out *exactly* when you want your macro to run. Do
you want the code to run when the user tries to save the document, or when
the user tries to close the document?

Post back with your answer to that, and any code you've put together (even
if it's not complete and/or doesn't work). And, let us know what version of
Word you and your users have.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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