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
159
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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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