Form VBA code for checking fields

L

Leslie Pollak

Hi,
I am using Word 2003.
On one of my forms, I have the following:
Existing Open ECN? No Yes (with a check box beside 'No' and 'Yes')
Existing ECN #: (Field to enter ENC number)
I need some sort of validation code on these thre fields.

Situation 1
------------
If the 'No' checkbox is checked then the 'YES' checkbox cannot be checked
and no data should be entered into the 'Existing ECN #:' field.

Situation 2
------------
If the 'Yes' checkbox is checked then the 'No' checkbox cannot be checked
and data has to be entered into the 'Existing ECN #:' field.

Would the code be easier if I used a drop down form field for the 'Yes/No'
instead of two separate checkbox fields?

Thanks
Leslie
 
J

Jay Freedman

Yes, the code would be easier with a dropdown. You wouldn't have to worry
about the exclusivity of the checkboxes (see
http://www.word.mvps.org/FAQs/TblsFldsFms/ExclusiveFmFldChbxs.htm for the
kind of mess that can cause).

With the dropdown, the logic is fairly easy:

If the dropdown shows "Yes" and the text field is empty, display an error.
If the dropdown shows "No" and the text field is not empty, display an
error.
Otherwise, proceed.

This logic should be called from macros that override the Save, Save As,
FilePrint, and FilePrintDefault commands. It's trickier to catch the case
where the user closes the form and Word then asks whether to save the
changes, because the events happen in the wrong order.

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

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