Form Text Field check

T

th

I have the following field bookmark as FName, LName, EmailAddr. These fields
cannot be emtpy when filling in the form. How can I check the if eg. FName
text field is empty, I will position the pointer back to FName field and
prompt a message that this field cannot be empty.

Thanks
 
J

Jean-Guy Marcil

th said:
I have the following field bookmark as FName, LName, EmailAddr. These fields
cannot be emtpy when filling in the form. How can I check the if eg. FName
text field is empty, I will position the pointer back to FName field and
prompt a message that this field cannot be empty.

Doing this with a regular protected form can be complicated. The only
reliable way I have found (and used) is to use the BeforeSave, BeforeClose
and BeforePrint event. For this, you need to create class modules... If you
have never done this, it can get complicated.

The reason I found I had to do it like that is that you have no control over
what the user does. How do you check fields that the user may no even click
into?
One way around that is to have an OnEntry macro that flags if a field has
been clicked in (or tabbed into) at least once. Then you need a macro that
checks if all required fields are not set to their default value or empty.
This requires thorough testing.

The easiest is to use a userform. When the user clicks on the OK button, it
is easy to check if the required fields have been filled in or not.
For more on userforms, see:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
and then
http://word.mvps.org/FAQs/Userforms/index.htm
 
T

th

Thanks Jean,

But is there any easy way out. That is I created a Template using the Form
Toolbar, I create TextBoxes to collect the First name, Surname, Email Addr
and go to the properties for each of those Text Form field and give them
Bookmark as FName, LName and EmailAddr. Can I create a simple macro and tag
it on each Textbox to Run Macro on Exit. How should be the VB code be like?
 
J

Jean-Guy Marcil

th said:
Thanks Jean,

But is there any easy way out. That is I created a Template using the Form

Not really.
Toolbar, I create TextBoxes to collect the First name, Surname, Email Addr
and go to the properties for each of those Text Form field and give them
Bookmark as FName, LName and EmailAddr. Can I create a simple macro and tag
it on each Textbox to Run Macro on Exit. How should be the VB code be like?

As I wrote before, you could have an OnExit macro attached to all formfields
that would check if the required formfields have been filled in. The problem
with this is that you will end up annoying users pointing out to them that
some fields are required and that that they are not filled in when the user
didn't even have the chance to fill them in yet. For the macro to be able to
tell if a user has been to a field, but failed to fill it out, you also need
an OnEntry macro for those fields setting a flag that the OnExit macro will
then use.

The easiest way is a userform to collect the necessary information and then
inject it in the appropriate formfields in the document. The userform could
kick in as soon as the document is created. It is much easier to perform
input validation in a userform then with formfields.

This is why I gave you the link in my previous post.
 

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