copying template drop down boxes

P

Paul

I have a form template which consists of two sheets. Under certain circumstances the second sheet is copied programatically depending on the value of a listbox. When the second sheet is copied (by copy and paste) the textboxes bookmarks are left with a blank value on the copied sheet. I need to access these copied textboxes to do some custom numbered codes. How do I give them a bookmark programatically to enter text bearing in mind it is also a part of a table

Thanks to anyone who reads and replies
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

If you want a bookmark name assigned to the formfields, you would have to
use the .Add method as in the following example:

Sub addrow()
'
' Macro created 02/02/03 by Doug Robbins
' To add a new row to a table containing formfields in every column
' automatically on exit from the last cell in the present last row of the
table
Dim rownum As Integer, i As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count
For i = 1 To ActiveDocument.Tables(1).Columns.Count
ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
"addrow"
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
'
End Sub

According to the help file, the .Name property of a formfield is Read/Write.
However, any time I try to assign a .Name to a formfield, I receive and
error message.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
P

Peter Hewett

Hi =?Utf-8?B?UGF1bA==?=

Presumably you mean a protected mode form that has FormFields in it. If
that's the case then you should be able to copy and paste the form fields.
However, the names of the FormFields cannot be carried across. This is
because FormField names are also bookmark names, and bookmarks names have to
be unique. So if you have any code that depends upon the FormField names then
it wont work for the copied FormFields.

After you have done your copy/paste just reprotect your document and tell
Word not to reset the FormFields to their default values, like this:
ActiveDocument.Protect wdAllowOnlyFormFields, True

HTH + Cheers - Peter
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Thanks Jay,

I'll have to try and remember that one.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top