#1
|
|||
|
|||
Reset "Button" to clear Word user-filled form, from all filled details.
Hello everyone,
I hope the post is in the right place. I have no knowledge of any code , so if there is an idea of how to solve the problem, please explain it in a simple way. Thank you I have built a Word form where there are drop-down boxes, boxes for free filling, date selection boxes. When I finished building the form, I locked it. After the users filling in the details , it is sent to be printed on a local printer. There is no need to save the form with the details. The filling is done about 20 times a day. In order to clear the details of the previous user, we close it, choose "Do not save changes", and open again. The second method is to open the "Undo" (down arrow), and undo all the changes in the form. Is it possible to add a kind of "button", when pressed, all the details filled, will be cleared at once? |
#2
|
|||
|
|||
It will depend on what type of field you have entered in your form.
|
#3
|
|||
|
|||
Quote:
The form has fields with a date picker , selecting from a scrolling down list, and boxes for free writing (for writing a number). The form has a place where the caption must remain unchanged. I've attached the file. There is no password to open the form (developers> Restrict edit> Stop protect). |
#4
|
||||
|
||||
I've added a macro to the file and included a button on the Quick Access Toolbar to run that macro. The macro is below...
Code:
Sub ClearForm() Dim aCC As ContentControl For Each aCC In ActiveDocument.ContentControls aCC.Range.Select If aCC.Type <> wdContentControlDropdownList Then aCC.Range.Text = "" Else aCC.Type = wdContentControlText aCC.Range.Text = "" aCC.Type = wdContentControlDropdownList End If Next aCC End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Quote:
It works great, but as soon as I've protected the form (The form must be protected), I get a message that there's a problem. I've attached : an image of the message and the highlighting of the problematic line (yellow). the 3 form steps. the form with the background Note: The form is printed on a sheet of paper with empty boxes (this is the background you see). |
#6
|
||||
|
||||
Are you using a password on the form protection? Assuming there is no password, and the form is protected before the macro is run, the following modifications would be required.
Code:
Sub ClearForm() Dim aCC As ContentControl ActiveDocument.Unprotect For Each aCC In ActiveDocument.ContentControls aCC.Range.Select If aCC.Type <> wdContentControlDropdownList Then aCC.Range.Text = "" Else aCC.Type = wdContentControlText aCC.Range.Text = "" aCC.Type = wdContentControlDropdownList End If Next aCC ActiveDocument.Protect wdAllowOnlyFormFields End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Quote:
I may have been wrong somewhere. I've done a process of: Fill out details, Activating the macro to clear the details, (happy) Protect form (no password). I will try again. |
#8
|
|||
|
|||
Quote:
The form is attached, I would appreciate it if you could explain to me how. |
#9
|
||||
|
||||
The amended file is attached.
You needed to save it in docm format so it can store a macro. The macro has been added in a new module and then I added a button on the QAT (it is the paintbrush).
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#10
|
|||
|
|||
Quote:
Also, there were a number of things that I had to change, not in the code but in one of the lists (font, etc.), I found that if I want to change something in the document itself , and keep the button work properly , the way that worked for me (which includes what you suggested) is: Developers> Restrict Edit> Stop Protection> Design Mode> Change What You Want> Click Design Mode Again> Enable "Restrict Edit" Check with the button that everything is fine. I would like to thank you for the tremendous help and patience. You made a number of blue-collar workers , very happy ! |
#11
|
|||
|
|||
Sorry I was out all day yesterday and couldn't get back to you. May I suggest:
Code:
Sub ClearForm() Dim oCC As ContentControl Dim lngProtType As Long lngProtType = -1 If ActiveDocument.ProtectionType <> wdNoProtection Then lngProtType = ActiveDocument.ProtectionType ActiveDocument.Unprotect End If For Each oCC In ActiveDocument.ContentControls On Error Resume Next oCC.Range.Editors.Item(1).Delete On Error GoTo 0 If oCC.Type = wdContentControlRichText Then oCC.Type = wdContentControlText If oCC.Type = wdContentControlDropdownList Then oCC.Type = wdContentControlText oCC.Range.Text = "" oCC.Type = wdContentControlDropdownList Else oCC.Range.Text = "" End If oCC.Range.Editors.Add (wdEditorEveryone) Next oCC ActiveDocument.Protect lngProtType End Sub Couple of things: 1) You don't need to select the content control to clear it. 2) If you are not using legacy "formfields" in your form then there is no reason to use that type of protection. 3) If you don't need to let the user's format the text then you don't need the rich text fields. With plain text fields, you can tab between the fields. |
#12
|
|||
|
|||
Quote:
The code works very smoothly. The day before yesterday, for an entire day, I tried to apply the code on this form and onto other short forms, and I encountered several problems. Yesterday I decided to follow your advice, and replaced all the boxes with rich text, into a simple text boxes. It made everything work Smooth. In A4 forms with lots of scroll down boxes (about 100), resetting takes a lot of time, (about 30 sec) but in the end it is done correctly. what do mean by saying : "If you are not using legacy "formfields" in your form then there is no reason to use that type of protection." ? How else could I build the form without users having the ability to change it? Thank you all for your responsiveness and professional help! |
#13
|
|||
|
|||
By adding editors to the content controls (the code I posted does that) and using No Changes, Read Only as the protection method,
|
#14
|
|||
|
|||
Quote:
Thank you , I'll try it and come back with an answer. |
#15
|
|||
|
|||
Quote:
When I applied them to more forms, especially with a few boxes, they work perfectly! I'll have to make do with it right now. I need to take the time and try to learn more about the "preparation" of the form for the code , all in order to make intelligent use of the useful codes that you have given me. Thank you very very much for your warm hospitality and helpful explanations. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
button "clear format", etc; anchors, functions and properties of OpenType, negative width of symbol? | tvan | Other Software | 1 | 07-18-2018 03:55 PM |
Using outlook form to enforce field to be filled in | megatronixs | Outlook | 1 | 01-21-2015 01:11 PM |
Text form filled shading | Barbara | Word | 2 | 04-25-2013 05:21 AM |
Add a "SAVE" Button to a form template? | Dave L | Word | 9 | 03-21-2012 07:04 PM |
How can create a form in Word 2007 that can be automatically filled? | artistech | Word | 0 | 08-04-2010 01:05 PM |