PDA

View Full Version : Create Text Boxes then Protect the contents



DaveUK
01-08-2007, 03:21 PM
Please could someone advise me of the code to create 3 text boxes and in TextBox 1 - The word "Title"
TextBox 2 - The word "Department"
TextBox 3 - The word "Absent"

I then want to protect TextBox 3 to prevent anyone deleting the contents.

I am new to Word VBA but have a fair knowledge of Excel VBA.

Any advice greatly appreciated.

fumei
01-08-2007, 04:36 PM
You want to create these dynamically, by code and only want to protect the third one? This seems a little odd. Can you explain this more?

DaveUK
01-08-2007, 07:04 PM
Is it possible to create them dynamically?

I couldn't find a reference for the TextBox (name etc) to code anything to relate to any TextBoxes. in order to produce code to protect it.

As i said i am familiar with Excel VBA but not word - as the object model is different (obviously i know) i am struggling to do this.

How could i refer to a TextBox and protect it?

Thanks for replying

fumei
01-08-2007, 11:51 PM
Is it possible to create them dynamically?

Uh, you wrote:
advise me of the code to create 3 text boxes"code to create" means, at least to me, code TO create, ie. dynamically. You are using code to create them. And yes, you can create them by code.

You can not refer to, and protect, a single textbox. That is, a formfield textbox. You could put the text formfield in its own Section by using a Continuous Section break. Then protect just that Section.

Formfields are protected for forms by reference to tghe Section they are in. Protection protects Sections.

So say Textbox 1, and Textbox 2, are in Section 1, with Textbox 3 in Section 2 - where Section 1 is separated by a Continuous Section break. If Section 2 is protected for forms, then only Textbox 3 will function protected.

But protection for forms does NOT mean the user can not change it. Text formfields in protected sections ARE available for change.

This is what protection does:

It locks ANY edits, other than input into formfields, for that Section.

So, if what you are calling for is Textbox 3 to be locked this is not possible. You could disable it though. If the Section is protected, and it is a formfield (and not disabled)...then the user can change it. They can not change anything else, but they CAN change the textbox.

If you want text inserted, that YOU inserted (by code I assume), then what you want to do is have a protected section - with textbox 1 and 2, UNPROTECT by code, insert the text you do NOT want the user to be able to change, then protect it again.

Voila. The text is inserted (but not into a textbox), and the user can not change it as it is in a protected Section. Textbox 1, and 2, being formfields WILL be changeable.

Use a bookmark to identify the location you want the inserted to go.

I have to ask again what you are really trying to do. You ask about a textbox with "Title". Formfield textboxes are for user input. Are you saying you want a textbox with "Title" in it, as default, and the user will change "Title" to something else? You could do that, but it is not the best design, IMO. For the user to change it they would have to select, or double click the formfield.

It would be better to have text "Title" with the formfield beside it. The user will know what the formfield is for. They can just enter the formfield and type.

Textboxes are for input. Using one for locked text is not really what they are designed for.