• using forms (Word 2000)

    • This topic has 43 replies, 5 voices, and was last updated 21 years ago.
    Author
    Topic
    #399885

    Hello everybody!

    I have a question, which is possibly easy to answer (but maybe I am too naive). I would like to create a form (that’s the easy part…). But now comes the point. When I use this form, I would like to still be able to insert tables, graphics and so on (all you can do in a usual word-document). For me it seems that it is not possible to realize this. Since I am usually a user of Excel, I have the idea that it must be possible to protect only some parts of a document, and leave other parts unprotected.
    The idea behind it: I want to create a template for reports. There I want to have some Checkboxes on the first page, through which I may choose, what kind of report the reader may expect. This can be done easily by creating a form. Unfortunately it is essential to have every freedom Word gives the author to write the report.
    Does somebody have a suggestion for this? Any help will be appreciated!!

    Many greetings, Porley

    Viewing 5 reply threads
    Author
    Replies
    • #776059

      In a form document, you can have protected and unprotected sections. To create a new section, position the insertion point where the new section should begin, and select Insert | Break… For a form document, a Continuous section break is most appropriate.
      To protect only some sections, select Tools | Protect document…, click the Forms option button and then click Sections… The “Section Protection” lets you specify which sections should be protected.
      You will only be able to insert tables, pictures etc. in unprotected sections.

      • #776773

        Hello Hans!

        Thank you very much for this answer!! Now my problem is partly fixed. Just to make things a little bit more complicated: one of the newly defined sections consists of a table with two columns. The left one should be unprotected, the right one should be protected.
        Do you have a solution for this as well?
        Does somebody else have an idea for this?

        Thank you for reading this post and thinking about this problem.

        Best regards,

        Porley

        • #776783

          You can’t have the first column of a table in an unprotected section and the second column in a protected section.

          One workaround is to put the entire table in a protected section, and to put a text field from the Forms toolbar in each cell of the first column. The user will only be able to enter plain text, not formatted text, graphics etc.

          Another workaround is to set that part of the document to two columns (Format | Columns…), and to put a one column table in each document column. Put the second document column in its own protected section.

        • #776784

          You can’t have the first column of a table in an unprotected section and the second column in a protected section.

          One workaround is to put the entire table in a protected section, and to put a text field from the Forms toolbar in each cell of the first column. The user will only be able to enter plain text, not formatted text, graphics etc.

          Another workaround is to set that part of the document to two columns (Format | Columns…), and to put a one column table in each document column. Put the second document column in its own protected section.

        • #777132

          The third workaround is to switch to Word 2003. The protection model, at least the one I saw demo’d, is completely different and much more flexible. Of course, if you can’t afford to buy all your users 2003, that isn’t going to work. sad

        • #777133

          The third workaround is to switch to Word 2003. The protection model, at least the one I saw demo’d, is completely different and much more flexible. Of course, if you can’t afford to buy all your users 2003, that isn’t going to work. sad

      • #776774

        Hello Hans!

        Thank you very much for this answer!! Now my problem is partly fixed. Just to make things a little bit more complicated: one of the newly defined sections consists of a table with two columns. The left one should be unprotected, the right one should be protected.
        Do you have a solution for this as well?
        Does somebody else have an idea for this?

        Thank you for reading this post and thinking about this problem.

        Best regards,

        Porley

    • #776060

      In a form document, you can have protected and unprotected sections. To create a new section, position the insertion point where the new section should begin, and select Insert | Break… For a form document, a Continuous section break is most appropriate.
      To protect only some sections, select Tools | Protect document…, click the Forms option button and then click Sections… The “Section Protection” lets you specify which sections should be protected.
      You will only be able to insert tables, pictures etc. in unprotected sections.

    • #776067

      I don’t know if this is relevant to your intention, but “rich” content, such as tables and graphics, can be stored as Autotext entries within a template. This means that it’s possible, for example, to have a specific “standard” graphic appear in a particular place, depending on the user’s form preferences.

      Alan

      • #779794

        Unfortunately it is not. The idea behind my question is as follows: In my company we often have to write reports. Due to some corporate identiity ideas, all these reports should formally look the same. On the first page there should be some checkboxes, with which you may mark, what kind of report it is (there are severel kinds). You should be able to mark this by checking one and unchecking all the others. What I found out is, that you can only realize this in a form when it is protected. But in a protected form you cannot use all the other features from word like inserting graphics, foot notes or stuff like that. Now I tried to seperate the form into protected and unprotected areas. Unfortunately, I have one area, where you can find a table with two columns. In one column you would find the mentioned checkboxes, the other one should be unprotected. This seems not to be possible (unless you do not use Word XP, which is out of discussion). But even if I could get rid of this problem, there seems to be another one. Even in an unprotected part of a form you cannot work properly (e.g. generate footnotes) unless you unprotect the form (which does not make sense, because then I wouldn’t need a form at all!) So for me it seems, that I cannot realize, what I want to…
        Maybe one of you has an idea, but I don’t know how to continue. By the way: the layout of the template is given, and I am not to change it in any way. I only may find a suitable way to work with it…

        Any idea will be appreciated!

        Best regards,

        Porley

        • #779801

          You could write macros that unprotect the document, change something that can only be done in an unprotected document, then reprotect it. Assign these macros to custom toolbar buttons, custom menu items and/or custom keyboard shortcuts. Skeleton code:

          ‘ unprotect
          ActiveDocument.Unprotect
          ‘ code to be executed in unprotected doc

          ‘ reprotect without clearing form fields
          ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

          • #779842

            Hans, and Porley of course,

            I found out something quite interesting. I’m experimenting with Office 2003 (Dutch version) a bit because we are considering upgrading from Office 97. In Word 97 VBA there is only 1 event on application level that you can use: DocumentChange. But in Word 2003 VBA there are a lot more. One of them is WindowSelectionChange and that gave me an idea.
            I created a document with 2 sections, marked section 1 as protected and section 2 as unprotected and then protected the document for forms.
            In a properly declared class module I put this code:

            Public WithEvents wdApp As Word.Application

            Private Sub WindowSelectionChange(ByVal Sel As Selection)
            If Sel.Information(wdActiveEndSectionNumber) = 1 Then
            ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
            Else
            ActiveDocument.Unprotect
            End If
            End Sub

            If I click, or move the cursor with the arrow keys in the unprotected Section 2, then the whole document is unprotected. And clicking, or moving the cursor with the arrow keys into Section 1 protects the whole document again, disabling the possibility to enter tekst in that section…
            I just found out, so I’m not sure of all the drawbacks and ramifications yet, but it sure has some perspective!

            I don’t know of these extra events are already present in Word 2000 VBA, but I heard from a co-worker that there are more than 1 in Word XP. Because I dont have that version here, I cannot tell if this particular event is present and my code is working in Word XP.

            JanB

            • #779854

              Jan,

              WindowSelectionChange was introduced in Word 2000, together with a whole slew of other new events, so your code should work there too. If Porley can use this, it would be nice to explain how to initialize the wdApp variable automatically when the document is opened.

              In your other post, you mentioned that you didn’t know the exact name of a toolbar in English. It is “Control Toolbox”. You can download an Excel spreadsheet with translations for several Office apps and several languages from Jan Karel Pieterse’s website http://www.jkp-ads.com[/url%5D.

            • #781007

              Hans,

              If Porley likes the idea, I’ll do that. And thanks for spreadsheet URL !

              JanB

            • #781036

              A good article on document and application events by Bill Coan, Take Control of Microsoft Word Through Events, can be found here.

              JanB

            • #781037

              A good article on document and application events by Bill Coan, Take Control of Microsoft Word Through Events, can be found here.

              JanB

            • #781008

              Hans,

              If Porley likes the idea, I’ll do that. And thanks for spreadsheet URL !

              JanB

            • #779855

              Jan,

              WindowSelectionChange was introduced in Word 2000, together with a whole slew of other new events, so your code should work there too. If Porley can use this, it would be nice to explain how to initialize the wdApp variable automatically when the document is opened.

              In your other post, you mentioned that you didn’t know the exact name of a toolbar in English. It is “Control Toolbox”. You can download an Excel spreadsheet with translations for several Office apps and several languages from Jan Karel Pieterse’s website http://www.jkp-ads.com[/url%5D.

            • #780678

              Brilliant idea! I’ve had odd results with WindowSelectionChange in other contexts, and it can drag down speed on a slower CPU, but because it can be much more granular than a section (you could even detect whether a user was trying to enter the “do not edit” column of a particular table), it’s a great approach to try.

              Bryan Carbonnell posted an example of the bits and pieces needed to catch a WindowSelectionChange event in post 196505 over on the VB/VBA board.

            • #781010

              Jefferson,

              Thanks for the URL to a interesting post.

              JanB

            • #781018

              Jefferson,

              Thanks for the URL to a interesting post.

              JanB

            • #780679

              Brilliant idea! I’ve had odd results with WindowSelectionChange in other contexts, and it can drag down speed on a slower CPU, but because it can be much more granular than a section (you could even detect whether a user was trying to enter the “do not edit” column of a particular table), it’s a great approach to try.

              Bryan Carbonnell posted an example of the bits and pieces needed to catch a WindowSelectionChange event in post 196505 over on the VB/VBA board.

          • #779843

            Hans, and Porley of course,

            I found out something quite interesting. I’m experimenting with Office 2003 (Dutch version) a bit because we are considering upgrading from Office 97. In Word 97 VBA there is only 1 event on application level that you can use: DocumentChange. But in Word 2003 VBA there are a lot more. One of them is WindowSelectionChange and that gave me an idea.
            I created a document with 2 sections, marked section 1 as protected and section 2 as unprotected and then protected the document for forms.
            In a properly declared class module I put this code:

            Public WithEvents wdApp As Word.Application

            Private Sub WindowSelectionChange(ByVal Sel As Selection)
            If Sel.Information(wdActiveEndSectionNumber) = 1 Then
            ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
            Else
            ActiveDocument.Unprotect
            End If
            End Sub

            If I click, or move the cursor with the arrow keys in the unprotected Section 2, then the whole document is unprotected. And clicking, or moving the cursor with the arrow keys into Section 1 protects the whole document again, disabling the possibility to enter tekst in that section…
            I just found out, so I’m not sure of all the drawbacks and ramifications yet, but it sure has some perspective!

            I don’t know of these extra events are already present in Word 2000 VBA, but I heard from a co-worker that there are more than 1 in Word XP. Because I dont have that version here, I cannot tell if this particular event is present and my code is working in Word XP.

            JanB

        • #779802

          You could write macros that unprotect the document, change something that can only be done in an unprotected document, then reprotect it. Assign these macros to custom toolbar buttons, custom menu items and/or custom keyboard shortcuts. Skeleton code:

          ‘ unprotect
          ActiveDocument.Unprotect
          ‘ code to be executed in unprotected doc

          ‘ reprotect without clearing form fields
          ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

        • #779820

          I think you discovered the single most frustrating thing for Word developers IMHO. It should be a consolation that there are millions of other developers all over the world that suffer with you… NOT! bwaaah
          If you really need the forms functionality – as we do – then there is really no alternativ I know of than to “hijack” all the relevant internal Word functions by writing your own Sub’s performing exactly the same task and storing those Sub’s in a add-in placed in the Word Startup folder. But even then there are quit a few drawbacks!

          For your particular problem there may be a work-around. From what you write I understand that you know how to use the checkboxes from the Forms toolbar. You can accomplish almost the same functionality with the checkboxes from the Toolset toolbar (not quite sure about this name, had to translate it from my Dutch version…). The VBA Sub’s handling these checkboxes must reside in the ThisDocument module.
          I have no personal experience with these checkboxes. But I have a few documents with a commandbutton to perform a certain task. And that works fine in a unprotected document. The only drawback in my case is that this commandbuttons (and other controls) are always printed – at least I haven’t discovered yet how to prevent that.. But if that is no problem for your situation then this could be something to experiment with.

          Good luck
          JanB

        • #779821

          I think you discovered the single most frustrating thing for Word developers IMHO. It should be a consolation that there are millions of other developers all over the world that suffer with you… NOT! bwaaah
          If you really need the forms functionality – as we do – then there is really no alternativ I know of than to “hijack” all the relevant internal Word functions by writing your own Sub’s performing exactly the same task and storing those Sub’s in a add-in placed in the Word Startup folder. But even then there are quit a few drawbacks!

          For your particular problem there may be a work-around. From what you write I understand that you know how to use the checkboxes from the Forms toolbar. You can accomplish almost the same functionality with the checkboxes from the Toolset toolbar (not quite sure about this name, had to translate it from my Dutch version…). The VBA Sub’s handling these checkboxes must reside in the ThisDocument module.
          I have no personal experience with these checkboxes. But I have a few documents with a commandbutton to perform a certain task. And that works fine in a unprotected document. The only drawback in my case is that this commandbuttons (and other controls) are always printed – at least I haven’t discovered yet how to prevent that.. But if that is no problem for your situation then this could be something to experiment with.

          Good luck
          JanB

    • #776068

      I don’t know if this is relevant to your intention, but “rich” content, such as tables and graphics, can be stored as Autotext entries within a template. This means that it’s possible, for example, to have a specific “standard” graphic appear in a particular place, depending on the user’s form preferences.

      Alan

    • #782490

      Hello Hans, hello Jan and all others!

      Thank you very, very much for your help in this matter! I am really amazed, how many ideas there are to solve the problem, and I am also surprised to see, that this is a topic of general interest (at least I get this impression). I am sorry, that I didn’t reply for such a long time, but I was ill (had a flue) and was not able to sit in front of a computer… But I hope, that you are still following this discussion.
      I tried the code Jan gave in his post. Unfortunately I was not able to make it run. Maybe Ja can post an example…
      “If Porley can use this, it would be nice to explain how to initialize the wdApp variable automatically when the document is opened.” Hans, do I understand you correctly, that you offer to explain? That would be very kind!!

      Once again let me give one big “Thanks” to you for your help!!

      Many greetings, Porley

      • #782502

        JanB wrote in post 341093 that he is willing to provide details on how to use his code. So I hope he reads this thread. (Otherwise, I will try to help)

        • #783293

          Hans, Porley,

          In a few minutes I’m leaving the office and have a very long weekend, returning tuesday or wednesday. If Porley cannot wait that long, and if the article I mentioned in my post 341104 in this thread isn’t clear enough to put things together, I hope Hans can help Porley out this time.

          Regards,
          JanB

        • #783294

          Hans, Porley,

          In a few minutes I’m leaving the office and have a very long weekend, returning tuesday or wednesday. If Porley cannot wait that long, and if the article I mentioned in my post 341104 in this thread isn’t clear enough to put things together, I hope Hans can help Porley out this time.

          Regards,
          JanB

      • #782503

        JanB wrote in post 341093 that he is willing to provide details on how to use his code. So I hope he reads this thread. (Otherwise, I will try to help)

      • #783527

        (Edited by HansV to correct typo pointed out by Phil Rabichow – thanks, Phil!)

        OK, here goes. Warning: working with this code is tricky. You must set up the document correctly before activating the code. In particular, you must already have set up the sections, and specified in Tools | Protect Document… which sections must be protected and which unprotected. In the following code, I have assumed that section 1 contains form fields and must be protected, and that section 2 must be unprotected. You can adapt the code for other situations.

        There are three parts to the code. The following must all be done in the Visual Basic Editor; from Word, press F1 to get there. Then click on the name of the document in the Project Explorer, to make sure that the code is stored with that document.

        1. The class module

        Select Insert | Class Module.
        In the Properties window, change its name to clsEvents.
        Type or paste the following code into the class module window:

        Public WithEvents app As Word.Application

        Private Sub app_WindowSelectionChange(ByVal Sel As Selection)
        If Sel.Information(wdActiveEndSectionNumber) = 1 And _
        ActiveDocument.ProtectionType = wdNoProtection Then
        ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
        ElseIf Sel.Information(wdActiveEndSectionNumber) = 2 And _
        ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
        ActiveDocument.Unprotect
        End If
        End Sub

        2. The standard module

        Select Insert | Module
        Name it basGlobals (this is not essential, but I like to name modules something else than Module1, Module2 etc.)
        Type or paste the following line into the module:

        Public MyClass As New clsEvents ‘ had a typo here originally: clsAppEvents instead of clsEvents

        3. The ThisDocument object module

        Double click ThisDocument.
        Type or paste the following code into the object module:

        Private Sub Document_Open()
        Set MyClass.app = Application
        End Sub

        This last procedure will start the whole thing when the document is opened. Close the Visual Basic Editor and return to Word. Make sure that the document is set up correctly, then close and save it. When you reopen it, it should behave as follows:
        – If you click in the first section, the document is protected; you can only fill in form fields.
        – If you click in the second section, the document is unlocked.

        If you make a mistake, you may not be able to unlock the document any more. In that case, switch to the Visual Basic Editor, open the ThisDocument module, and click in the margin to the left of Private Sub app_… to create a breakpoint. Switch back to Word and click in the document. The code will pause at the first line of the event procedure. Click the Stop button. Now, you can unprotect the document from the Tools menu.

        I have attached a demo document. It does nothing more than the above.

        • #783802

          Hello Hans!

          Thank you very much for your assistance! I tried your code out, and it worked very well. So thanks again. I could never have worked this out on my own…
          Unfortunately I found one other problem: I want to use this form as a template, so that every user is able to use it on any computer in our network. If I choose File | new | MyTemplate, I receive a new document without the macros, and the macros from MyTemplate will not be used. Is there also a way to get the functionality into the document, which is based on MyTemplate?
          This is the last thing to do for me, the rest already works perfectly (thanks to you and Jan who will hopefully have a nice weekend).
          I wish you a nice weekend!

          Many grateful greetings, Porley

          • #783822

            When you create a new document based on a template, the macros are not copied into the document, but the document does have access the the macros in the template. You need only one small addition to activate the macros when you create a new document from the template: a Document_New procedure in the ThisDocument module of the template:

            Private Sub Document_New()
            Set MyClass.app = Application
            End Sub

            As you see, it looks like the Document_Open procedure that is already there. Make sure that the document protection is set correctly when you save the template.

            • #783824

              Thank you very much!

              You really safed my weekend….

              Best regards, Porley

            • #783825

              Thank you very much!

              You really safed my weekend….

              Best regards, Porley

          • #783823

            When you create a new document based on a template, the macros are not copied into the document, but the document does have access the the macros in the template. You need only one small addition to activate the macros when you create a new document from the template: a Document_New procedure in the ThisDocument module of the template:

            Private Sub Document_New()
            Set MyClass.app = Application
            End Sub

            As you see, it looks like the Document_Open procedure that is already there. Make sure that the document protection is set correctly when you save the template.

        • #783803

          Hello Hans!

          Thank you very much for your assistance! I tried your code out, and it worked very well. So thanks again. I could never have worked this out on my own…
          Unfortunately I found one other problem: I want to use this form as a template, so that every user is able to use it on any computer in our network. If I choose File | new | MyTemplate, I receive a new document without the macros, and the macros from MyTemplate will not be used. Is there also a way to get the functionality into the document, which is based on MyTemplate?
          This is the last thing to do for me, the rest already works perfectly (thanks to you and Jan who will hopefully have a nice weekend).
          I wish you a nice weekend!

          Many grateful greetings, Porley

        • #785734

          Hi Hans, Porley

          I had a wonderful long weekend!
          Thanks Hans, for taking care of this.
          I have one suggestion for the code to be more generic:

          Private Sub app_WindowSelectionChange(ByVal Sel As Selection)
          If Sel.Information(wdActiveEndSectionNumber).ProtectedForForms = True And _
          ActiveDocument.ProtectionType = wdNoProtection Then
          ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
          ElseIf Sel.Information(wdActiveEndSectionNumber).ProtectedForForms = False And _
          ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
          ActiveDocument.Unprotect
          End If
          End Sub

          Regards,
          Jan

        • #785735

          Hi Hans, Porley

          I had a wonderful long weekend!
          Thanks Hans, for taking care of this.
          I have one suggestion for the code to be more generic:

          Private Sub app_WindowSelectionChange(ByVal Sel As Selection)
          If Sel.Information(wdActiveEndSectionNumber).ProtectedForForms = True And _
          ActiveDocument.ProtectionType = wdNoProtection Then
          ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
          ElseIf Sel.Information(wdActiveEndSectionNumber).ProtectedForForms = False And _
          ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
          ActiveDocument.Unprotect
          End If
          End Sub

          Regards,
          Jan

      • #783528

        (Edited by HansV to correct typo pointed out by Phil Rabichow – thanks, Phil!)

        OK, here goes. Warning: working with this code is tricky. You must set up the document correctly before activating the code. In particular, you must already have set up the sections, and specified in Tools | Protect Document… which sections must be protected and which unprotected. In the following code, I have assumed that section 1 contains form fields and must be protected, and that section 2 must be unprotected. You can adapt the code for other situations.

        There are three parts to the code. The following must all be done in the Visual Basic Editor; from Word, press F1 to get there. Then click on the name of the document in the Project Explorer, to make sure that the code is stored with that document.

        1. The class module

        Select Insert | Class Module.
        In the Properties window, change its name to clsEvents.
        Type or paste the following code into the class module window:

        Public WithEvents app As Word.Application

        Private Sub app_WindowSelectionChange(ByVal Sel As Selection)
        If Sel.Information(wdActiveEndSectionNumber) = 1 And _
        ActiveDocument.ProtectionType = wdNoProtection Then
        ActiveDocument.Protect NoReset:=True, Type:=wdAllowOnlyFormFields
        ElseIf Sel.Information(wdActiveEndSectionNumber) = 2 And _
        ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
        ActiveDocument.Unprotect
        End If
        End Sub

        2. The standard module

        Select Insert | Module
        Name it basGlobals (this is not essential, but I like to name modules something else than Module1, Module2 etc.)
        Type or paste the following line into the module:

        Public MyClass As New clsEvents ‘ had a typo here originally: clsAppEvents instead of clsEvents

        3. The ThisDocument object module

        Double click ThisDocument.
        Type or paste the following code into the object module:

        Private Sub Document_Open()
        Set MyClass.app = Application
        End Sub

        This last procedure will start the whole thing when the document is opened. Close the Visual Basic Editor and return to Word. Make sure that the document is set up correctly, then close and save it. When you reopen it, it should behave as follows:
        – If you click in the first section, the document is protected; you can only fill in form fields.
        – If you click in the second section, the document is unlocked.

        If you make a mistake, you may not be able to unlock the document any more. In that case, switch to the Visual Basic Editor, open the ThisDocument module, and click in the margin to the left of Private Sub app_… to create a breakpoint. Switch back to Word and click in the document. The code will pause at the first line of the event procedure. Click the Stop button. Now, you can unprotect the document from the Tools menu.

        I have attached a demo document. It does nothing more than the above.

    • #782491

      Hello Hans, hello Jan and all others!

      Thank you very, very much for your help in this matter! I am really amazed, how many ideas there are to solve the problem, and I am also surprised to see, that this is a topic of general interest (at least I get this impression). I am sorry, that I didn’t reply for such a long time, but I was ill (had a flue) and was not able to sit in front of a computer… But I hope, that you are still following this discussion.
      I tried the code Jan gave in his post. Unfortunately I was not able to make it run. Maybe Ja can post an example…
      “If Porley can use this, it would be nice to explain how to initialize the wdApp variable automatically when the document is opened.” Hans, do I understand you correctly, that you offer to explain? That would be very kind!!

      Once again let me give one big “Thanks” to you for your help!!

      Many greetings, Porley

    Viewing 5 reply threads
    Reply To: Reply #781007 in using forms (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel