User form in Word, need VBA to either force entry in fields or remind user before saving...

Guitarmageddon

Board Regular
Joined
Dec 22, 2014
Messages
161
So I have a two-page form created by a user to get field locations to send up some information. there are about 30 or so text fields that the owner of this form wants to be mandatory to enter.

I came across this macro, which works for LEGACY form fields and not current content control text fields.

VBA Code:
Sub MustFillIn()
    If ActiveDocument.FormFields("MyRequiredField").Result = "" Then
        Do
            sInFld = InputBox("Required Installation is required, please fill in below.")
        Loop While sInFld = ""
        ActiveDocument.FormFields("MyRequiredField").Result = sInFld
    End If
End Sub

This works, but the presentation of the popup is pretty annoying and clunky. I'd also have to duplicate something like 30 modules to get this to run. There has to be a better way?

Can I have some VBA to scan ANY of the "activeDocument.FormFields" for blanks and then remind the user to enter before they are allowed to save or close the file? Seems way easier than crafting a bespoke module for every specific form field name. I would greatly appreciate the help.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Looks like I may be able to do something like this, and simply check if the text fields are blank or not. But what would be the best way to throw this message up if the user tries to save or close without the data being enered?

VBA Code:
Sub MustFillIn()
If Text1 = "" Or Text2 = "" Or Text7 = "" Or Text8 = "" Or Text9 = "" Or Text10 = "" Or Text11 = "" Then
   MsgBox "Please ensure you have entered data in the orange required fields."
   Exit Sub
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top