Required Text Box

T

TechWriter

Is there a way to make a field required on a form? e.g., prevent a user from
saving a form if a particular field is left blank and displaying a message
telling the user which field needs to be completed.

Thanks for your help.
 
M

macropod

Hi TechWriter,

A macro could be used to do this but, if the user's security settings are too high, or the users elects to disable macros in the
document, then the macro approach won't work. The following macro, when placed in the document's ‘ThisDocument’ module, prevents the
document being closed if it contains any formfields that have not been filled in:
Private Sub Document_Close()
Dim aField As FormField
For Each aField In ActiveDocument.FormFields
If Trim(aField.Result) = "" Then
MsgBox "Please complete all the items"
ThisDocument.Reload
Exit Sub
End If
Next aField
End Sub

You can the following version to check a specific formfield by referencing the field's bookmark name (assuming you've set its
properties to create one):
Private Sub Document_Close()
If Trim(ActiveDocument.Bookmarks("BkMrk").Range.Text) = "" Then
MsgBox "Please complete the nominated item."
'ThisDocument.Reload
Exit Sub
End If
End Sub
where 'BkMrk' is the name of the bookmark. Change the message to suit.

Cheers
 

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