How to Reset Form Fields in a Word Fillable Form
Creating a fillable form in Microsoft Word can greatly streamline data collection and processing. However, ensuring that users can easily reset and reuse the form is equally important. In this tutorial, we'll walk through the process of adding a Reset Form command button to your Word fillable form that clears all form fields with just a click.
Step 1: Prepare Your Document
Before adding the reset button, ensure that your document is saved as a macro-enabled file type. To do this:
Navigate to the "File" menu.
Select "Save As."
Choose a location to save your document.
In the "Save as type" dropdown menu, select "Word Macro-Enabled Document."
Click "Save" to confirm.
Step 2: Insert the Command Button
Place your cursor where you want to insert the command button within your form.
Go to the "Developer" tab in the Word ribbon.
From the "Legacy Forms" dropdown menu, select "Command Button" under ActiveX controls.
Double-click the button to open the Visual Basic for Applications (VBA) editor.
Step 3: Add VBA Code
In the VBA editor, paste the provided code. This code is responsible for clearing form fields and is available below.
Review the code to understand its functionality. It unprotects the document, clears form fields, and reprotects the document.
Save and close the VBA editor.
Private Sub CommandButton1_Click()
Dim cc As ContentControl
Dim ff As field
' Unprotect the document to allow form field entry
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
' Clear content control form fields
For Each cc In ActiveDocument.ContentControls
Select Case cc.Type
Case wdContentControlText ' Text content control
cc.Range.Text = ""
Case wdContentControlComboBox ' Combo box content control
cc.Range.Text = ""
Case wdContentControlDate ' Date picker content control
cc.Range.Text = "" ' Clear the date value by setting the Range.Text property to an empty string
Case wdContentControlCheckBox ' Checkbox content control
cc.Checked = False ' Uncheck the checkbox
End Select
Next cc
' Reset legacy form fields
ActiveDocument.ResetFormFields
' Protect the document again if needed
If ActiveDocument.ProtectionType = wdNoProtection Then
' Replace "YourPassword" with the actual password if your document is password-protected
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
Step 4: Customize the Command Button
Right-click the command button and select "Properties."
In the properties window, rename the button to "Reset Form" in the caption field.
Close the properties window.
Step 5: Finalize Document Protection
Ensure you're in design mode by clicking the "Design Mode" button in the Developer tab.
Navigate to the "Restrict Editing" option.
Check the box to "Allow only this type of editing in the document" and select "Filling in forms" from the dropdown menu.
Click "Yes, start enforcing protection" and choose NOT to set a password.
Click "OK" to confirm.
Step 6: Test Your Form
Enter data into your form fields.
Click on the "Reset Form" button to clear all form fields.
Verify that text boxes are empty, checkboxes are unchecked, and dropdown lists reset to their default selection.
Step 7: Additional Considerations
If your form utilizes content control form fields instead of legacy form fields, the same reset functionality can be applied. The provided VBA code is designed to clear both types of form fields.
Ensure that the first item in your dropdown lists is a default selection, as the reset function will revert to this option.
Conclusion Congratulations! You've successfully added a command button to your Word fillable form, allowing users to easily reset and reuse the form. This simple but powerful feature enhances the user experience and streamlines data management. Share this tutorial with others to help them optimize their form creation process. Be sure and subscribe to my YouTube Channel and check out the other Tutorials on my website for more helpful tips!