How to verify blank form fields on exit?

C

charlie6067

For example, a protected form has three fields: FName, Initial, and
LName. I need help writing an On Exit macro for the LName field that:

1. Reviews all form fields for blanks.
2. Displays the name of the blank form field(s) so user can correct.

I've tried using bits of code from other postings but can't seem to get
anything to work.

Thanks,
Charlie
charlie6067
 
J

Jay Freedman

Instead of one check on exit from the last field, I'd recommend a separate
validation for each field. The reason is that the user could use the mouse
to leave the FName or Initial field without ever going into the LName field,
and then no validation would be done.

You can use the macro in
http://www.word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm as a basis.
Change the If statement to

If Len(Trim(.Result)) = 0 Then

to check for a field that's empty or contains only blank characters.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
C

charlie6067

Thanks Jay - that worked. Yes, it is better to alert the user right
after the error instead at the end of the form. I appreciated the code.

Charlie
charlie6067
 

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