Create a Reset Form Button in Word - How to Reset Form Fields in Word Fillable Forms
Вставка
- Опубліковано 17 лип 2024
- How to reset form fields in a Word fillable form by adding an ActiveX command button that when a user clicks it, all of the form fields will be cleared out. Create a reset form button in Word that will work to clear both Legacy form fields and Content Control form fields. We will insert a command button on our form and then program the button with the VBA code below. This button will uncheck a checked box, clear text from a text box and reset drop-down lists to the initial value. This Reset Form button will allow users to clear existing data that had been filled into the form so they can quickly and easily re-use the form like new. The Reset button is helpful when saving your form document as a Template file type will not support other features in the form.
Here is the VBA Code we used in our Reset Form button (notice two areas where I indicate you have to replace and insert angled brackets as the UA-cam Description doesn't allow those characters):
Private Sub CommandButton1_Click()
Dim cc As ContentControl
Dim ff As field
' Unprotect the document to allow form field entry
If ActiveDocument.ProtectionType [Insert Angled Brackets] 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
Private Sub CommandButton1_Click()
Dim cc As ContentControl
Dim ff As field
' Unprotect the document to allow form field entry
If ActiveDocument.ProtectionType [Insert Angled Brackets] 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
TIMESTAMPS ⏰
00:00 Reset Form Button in Word
00:14 Legacy & Content Control Form Fields
00:26 Prepare Form for Reset Button
01:02 Insert Reset Form Button & VBA Code
02:12 Format Reset Form Button
02:34 Test the Reset Form Button
03:56 Reset Content Control Form Fields
COURSE 🎒
Create Fillable Forms, Surveys & Questionnaires in Microsoft Word like a Pro: • Creating Fillable Form...
WATCH NEXT 📺 Make Fillable Form Reusable in Word: • How to Make Fillable F...
CHANNEL LINK 📺
/ @sharonsmith
Visit my Channel page on UA-cam to see all my videos, playlists, community posts and more!
TEMPLATES 📄
Check out my helpful list of templates available for purchase: creatoriq.cc/43c51cv
Thank you for supporting my channel! 🌟
FREE DOWNLOADS ⬇️
✦ Visit mailchi.mp/6a0859ea0844/sharo... to sign-up for my e-mail list and get FREE downloads of super helpful spreadsheet formulas, dashboards and Org Chart templates for HR professionals.
CONNECT WITH ME 📎
Visit my website: www.sharonsmithhr.com for more information, tools and resources.
LinkedIn: / sharonsmithhr
Twitter: / sharonsmithhr
Instagram: / sharonsmithlearning
Facebook: / sharonsmithlearning
sharon , always amazing , thanks for this video
I'm so glad you found it helpful! Thanks so much for watching my videos!
Great video!
Thanks Linda!
Hi Sharon
I watched your Fila Le forms for Mac and the one for reset button. I am just wondering how do you create the reset button and submit button in one button in Mac . Mac version does not have the legacy tool and I have been unable to add it in.
Your help would be appreciated.
Thanks
Michael
Hello Michael! Thanks for watching my videos. Word for Mac does not natively support the same level of form control functionality as Word for PC, including the insertion of a Submit button directly within the document. However, there are some workarounds and alternative approaches you can consider:
Macro-Enabled Documents:
You can create a macro that performs a similar function to a Submit button. This would involve writing a VBA (Visual Basic for Applications) macro that handles the submission process.
On Word for Mac, you can create and run macros, but the process to set them up and use them might be more complex compared to Word for PC.
Online Forms:
Use Microsoft Forms or Google Forms to create an online form and include a link to this form in your Word document. This can serve as a substitute for a Submit button.
Here is my video on how to create Online forms with Microsof Forms: ua-cam.com/video/VMrGTMy2gaM/v-deo.html
Here is my video on how to create Online forms with Google Forms: ua-cam.com/video/VBFOOC8enVI/v-deo.html
Hope this helps!
Your video has been a huge help with my work project. I would love take classes from you to further my knowledge in form making. Do you offer classes?
I'm so glad to hear that! Yes, I actually have a UA-cam Course on How to Create Fillable Forms in Microsoft Word: ua-cam.com/play/PLb80efKTbWuNzAyHVMYrPOS7itBm5gWVs.html You are welcome to watch the intro video and then if interested, it is a paid course on UA-cam and you can access a course workbook PDF and the sample form templates to go along with it.
I'm glad you like my videos and that they have helped you out at work. I wish you the best! Thanks for watching my Channel!
@@SharonSmith Do you have a price for the whole series or are you only selling them per course?
Sharon, how do I put a "insert a blank page" command button so that when it's clicked, a new blank page is added?
I am getting a ambiguous name error with this line: Private Sub CommandButton1_Click. Is there a way to fix?
Hello! The "ambiguous name error" in VBA typically occurs when there are multiple objects with the same name in the project, causing VBA to be unsure which one you're referring to. To fix this issue, you can try one or more of the following steps:
1. Rename the Subroutine: Change the name of the subroutine CommandButton1_Click to something unique. For example:
Private Sub ResetFormButton_Click()
2. Ensure Unique Object Names: Make sure there are no other objects (such as buttons or shapes) with the same name CommandButton1 in your Word document. If there are, you can rename them to ensure uniqueness.
3. Explicitly Qualify the Object: If you have multiple modules or objects with similar names, you can explicitly qualify which one you're referring to. For example:
Private Sub UserForm1_CommandButton1_Click()
This approach specifies the user form (UserForm1) that contains the command button. Make sure to replace UserForm1 with the actual name of your user form.
After making these changes, ensure you update the references to the subroutine throughout your code to match the new name.
I hope this helps! Thanks for watching my videos!
@@SharonSmith It worked! Thank you.
@@maxeenandjasminehill1542 Awesome! Glad to hear it!
I do not see where we can copy the active X commands
Never mind
Hello! Hopefully you found it in the video description. If you are on mobile, you have to expand it below the video - it is a little easier to find on desktop. Hope this helps! Thanks for watching!
Hoping you found it in the video description. Take care!