PDA

View Full Version : Forcing Users to input data into a TextFormField



ctengelen
09-12-2006, 12:35 PM
Hi all you Gurus,

I have a new question in my quest for fill-in forms:

We have an on-line Template on our shared drive. In it we have a number of TextFormFields that the user MUST input something. Well, not all do that and I would like to add some kind of "If null" statement to my code that forces the user to type some information into those TextFormFields.

I only used TextFormFields, DropDownFormField and CheckBoxeFormFields in this form and the user enters data directly into the form. The form works great - with the exception of our crafty (lazy) :( users that omit vital information.

I would like a macro that stops the user from leaving the field(s) and a message pops up alerting him/her that data is needed and they can't go on until data is entered.

It is getting to be a bother sending the documents back and asking for the missing data. :whip

Can anyone help me please?? :help

Trudy

Gavint
09-12-2006, 06:40 PM
One solution would be to do a check on the contents of text fields etc when the user clicks the OK button.

Private Sub cmdOK_Click()
If Textbox1 = "" Then
MsgBox ("You must enter this and that message"), , "Data Missing"
Else
Me.Hide
End If
End Sub

fumei
09-13-2006, 12:45 AM
Gavint, if you read the post, these are text formfields. Therefore, they are not ON a userform, therefore there is no OK button.

Dr@g0nfly
03-08-2007, 10:36 AM
Would it be worth it to code such a command in an "on Exit" macro which was referenced at the pertinent fields?

Just a thought, from a little mind, but they say you can start a forest fire with one match!:*)

fumei
03-08-2007, 10:00 PM
The question really is...at what point are you validating whether there is content, or not? Formfields can be jumped around in any order.

What if the user leaves Text1 blank, fills in Text2, selects Check1...THEN goes back and fills in Text1.

Technically speaking, there is nothing wrong with that. You do not have to complete formfields in sequence. Nor, IMO, should you.

So, you have users that leave blank formfields. OK. Let 'em. What exactly is the issue? They close/save the document leaving something blank?

Then the issue is....in saving/closing the document, and it is THERE you catch it.

Sub FileSave()
If ActiveDocument.Formfields("Text1").Result = "" Then
Msgbox "Text1 is blank. This is a required field."
Exit Sub
Else
ActiveDocument.Save
End if
End Sub
Or a version thereof. They try and save it...Text1 is blank...they can't save it.

You can do the same thing with trying to close it.

I will warn you. This kind of error trapping can get quite extended if you attempt to fully implement.

Note that if the user put in "The heck with you..." in Text1, then...it is NOT blank, and there you go.

If you are ONLY trapping for blank vs not-blank, that is easy enough.

I had one case that it was crucial that the inputs be absolutely correct. There were required elements, and nothing else was acceptable. The parsing of the text, and checking took a LOT of code. The error trapping was over 90% of the code.

If ANY text other than blank is acceptable, then it is a piece of cake.

You could make each formfield have a OnExit checking, but I would recommend against this route. For one thing, even if you DO check, and find it is blank, it is not as easy as you may think to do anything about it.

Try it. Try selecting the formfield you are leaving within the exiting code. Say you are exiting Text1, try doing error trapping on the contents of Text1 with an OnExit macro for Text1.

Nope. The best route is catch it when they either Save, or Close.