Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2018, 09:01 AM
Rafi Rafi is offline Reset "Button" to clear Word user-filled form, from all filled details. Windows 7 64bit Reset "Button" to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset "Button" to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default 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?
Reply With Quote
  #2  
Old 11-20-2018, 11:58 AM
gmaxey gmaxey is offline Reset "Button" to clear Word user-filled form, from all filled details. Windows 7 32bit Reset "Button" to clear Word user-filled form, from all filled details. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

It will depend on what type of field you have entered in your form.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-20-2018, 05:48 PM
Rafi Rafi is offline Reset "Button" to clear Word user-filled form, from all filled details. Windows 7 64bit Reset "Button" to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset "Button" to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
It will depend on what type of field you have entered in your form.
Hello and thanks for the quick reply.

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).

Attached Files
File Type: docx טופס מילוי_נעול.docx (27.2 KB, 27 views)
Reply With Quote
  #4  
Old 11-20-2018, 07:32 PM
Guessed's Avatar
Guessed Guessed is offline Reset "Button" to clear Word user-filled form, from all filled details. Windows 10 Reset "Button" to clear Word user-filled form, from all filled details. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Attached Files
File Type: docm טופס מילוי_נעול.docm (33.8 KB, 36 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 11-20-2018, 09:20 PM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
Hello and thank you very much for the answer.

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).
Attached Images
File Type: png VB.png (100.0 KB, 78 views)
Attached Files
File Type: pdf form stages.pdf (227.2 KB, 18 views)
File Type: docx מילוי טפסים_תאי&#.docx (207.0 KB, 17 views)
Reply With Quote
  #6  
Old 11-20-2018, 10:22 PM
Guessed's Avatar
Guessed Guessed is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 10 Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
This code will fail if the form is not already protected or has a password so a better solution would be to add more lines of code to check first.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 11-20-2018, 10:37 PM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
This code will fail if the form is not already protected or has a password so a better solution would be to add more lines of code to check first.
there is no password .
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.
Reply With Quote
  #8  
Old 11-20-2018, 10:53 PM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
This code will fail if the form is not already protected or has a password so a better solution would be to add more lines of code to check first.
I'm sorry, I tried but I do not know how to do it.
The form is attached, I would appreciate it if you could explain to me how.
Attached Files
File Type: docx מילוי טפסים_תאי&#.docx (207.0 KB, 11 views)
Reply With Quote
  #9  
Old 11-21-2018, 02:03 AM
Guessed's Avatar
Guessed Guessed is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 10 Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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).
Attached Files
File Type: docm מילוי טפסים_תאי&#.docm (213.8 KB, 37 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #10  
Old 11-21-2018, 02:49 AM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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).
Works perfectly !!

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 !
Reply With Quote
  #11  
Old 11-21-2018, 05:20 AM
gmaxey gmaxey is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 32bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #12  
Old 11-27-2018, 12:16 AM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
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.
First of all, I'm sorry for the late reply.

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!
Reply With Quote
  #13  
Old 11-27-2018, 05:13 AM
gmaxey gmaxey is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 32bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

By adding editors to the content controls (the code I posted does that) and using No Changes, Read Only as the protection method,
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #14  
Old 11-27-2018, 06:00 AM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
By adding editors to the content controls (the code I posted does that) and using No Changes, Read Only as the protection method,

Thank you , I'll try it and come back with an answer.
Reply With Quote
  #15  
Old 11-28-2018, 11:29 PM
Rafi Rafi is offline Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Windows 7 64bit Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. Office 2016
Novice
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details.
 
Join Date: Nov 2018
Location: Israel
Posts: 14
Rafi is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
This code will fail if the form is not already protected or has a password so a better solution would be to add more lines of code to check first.
The two codes you -Guessed & gmaxey- provided me , are working very effectively!

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.
Reply With Quote
Reply

Thread Tools
Display Modes


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
Reset &quot;Button&quot; to clear Word user-filled form, from all filled details. 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft