PDA

View Full Version : Problem when selecting a FormField



augf87
08-29-2009, 11:56 AM
Hi. I have a FormField in a documents, and some code that uses the info of the FormField when it's selected. If the doc is unlocked, the code works perfectly. However, when I lock it, the FormField isn't recognized as selected (Selection.Formfields.count = 0).
Is there any way to solve this?

Thanks in advance

lucas
08-29-2009, 12:26 PM
maybe post your document if you can. click on post reply and then scroll down and look for manage attachements.

Did you try unprotecting - running you code - reprotecting?


I also question the need to "select" It would help to see what you are doing.

Tinbendr
08-29-2009, 06:25 PM
Maybe this link (http://word.mvps.org/faqs/tblsfldsfms/GotoFormField.htm) will help.

augf87
08-30-2009, 12:05 AM
I have different formfields in a document, I write down some numbers and then I do some calculations with them. Because I may copy the formfields to different parts of the doc, I can't handle them with bookmark names.

The code I'm having trouble with should detect the formfield that is currently selected and delete its content, but when I do "Selection.Formfields(1).Result = "" " says "Object not found". If the documents is unlocked, it works, otherwise it doesn't.

I hope you can understand my problem. Thanks in advance.

Tinbendr
08-30-2009, 01:54 PM
OK, what about this link (http://word.mvps.org/FAQs/TblsFldsFms/GetCurFmFldName.htm).

augf87
08-30-2009, 09:44 PM
I'm not working with FormFields names, because if I copy a formfield, the new name will be just blank

lucas
08-31-2009, 04:12 AM
If the documents is unlocked, it works, otherwise it doesn't.

I hope you can understand my problem. Thanks in advance.

I don't understand at all. First of all if unlocking works, why don't you unlock it? I assume you mean unprotect.

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="pwd"
'your code
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="pwd"

Tinbendr
08-31-2009, 04:46 AM
I'm not working with FormFields names, because if I copy a formfield, the new name will be just blankBut, you should be able to use the Selection.Bookmarks(Selection.Bookmarks.Count) without the Name.

BTW, you should be using VBA to insert those formfields for you, NAMING them as you go. As a matter of fact, all of the properties listed in the FF window can be set, giving you much more control over your document.

Give us a generic document to work with.

fumei
09-01-2009, 12:45 PM
"BTW, you should be using VBA to insert those formfields for you, NAMING them as you go."

YES YES YES!

Do NOT copy formfields. Do NOT copy formfields. It is a bad bad bad idea.

For precisely the reason you see, they have no names! Not only that......they do not have bookmarks either! Again, formfields have bookmarks...they are NOT bookmarks.

BTW: I also wonder about the use of "select".

"The code I'm having trouble with should detect the formfield that is currently selected and delete its content"

Ummmm, why? Formfields are for users to put information/data in...not you, the developer. If YOU, as the developer, have to put in data/information, there are other ways than formfields. Perhaps if you explained - exactly - what it is you are attempting to do, and why?

It sounds like you are testing for a user input, and if "incorrect" blanking out what they have entered. Is this correct?