Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Trying to change the name of a formfield

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
skbrown14 - 06 Feb 2005 00:45 GMT
I have code that inserts autotext entries into a document.  I need to change
the name of the form fields that are in those autotext entries based on the
number of those entries that are inserted into the document.

For example, I have a form field called DICTATION_N1_x in the autotext
entry.  If I insert 2 copies of the autotext entry, I want the first copy to
have the form field named "DICTATION_N1_1"  and the second copy to have the
form field named "DICTATION_N1_2".

In doing this programmatically, I am unable to set the .Name property of the
form field to a variable.  I am getting an automation error.  Does anyone
know how to set the name property on a form field programmatically to a
variable?

Thanks in advance for any help!
Doug Robbins - Word MVP - 06 Feb 2005 01:09 GMT
ActiveDocument.FormFields(1).Name = "Text3" changes the name of the first
formfield in the document to Text3 for me.

What do you mean by "a variable"?  Show us the code that you are trying to
use.

> I have code that inserts autotext entries into a document.  I need to change
> the name of the form fields that are in those autotext entries based on the
[quoted text clipped - 11 lines]
>
> Thanks in advance for any help!
skbrown14 - 06 Feb 2005 01:49 GMT
Thanks and sorry about not elaborating, but here is the code I'm using:

Public Sub ChangeDictBMName(DictAcr As String)
Dim ff As FormField
Dim tempName As String

On Error GoTo ErrHndler

For Each ff In ActiveDocument.FormFields

   If Mid$(ff.Name, 11, Str(Len(DictAcr))) = DictAcr And Right$(ff.Name, 1)
= "x" Then
       tempName = Left$(ff.Name, Len(ff.Name) - 1) & Str$(glbThisSuppQty)
       ff.Name = tempName
   End If
   
Next ff

Exit Sub

ErrHndler:
   ret = MsgBox(Err.Number & ": " & Err.Description, , "LC Standard Report:
ChangeDictBMName")

End Sub

Before I enter into this code, I've looked for the autotext entry to see if
it is already inserted into the document by searching for a bookmark, and
determined how many of that entry has already been inserted into the
document.  That number is stored in glbThisSuppQty.  I then insert the
autotext entry then go into the code above.  The passed argument, DictAcr,
holds values such as "N", "PR", "PL", etc.  One autotext entry has multiple
form fields named, for example, "DICTATION_N1_x", "DICTATION_N2_x",
"DICTATION_N3_x", etc.  The "x" needs to be changed to the number of copies
of that autotext entry.

I hope this helps a little.

Thanks

> ActiveDocument.FormFields(1).Name = "Text3" changes the name of the first
> formfield in the document to Text3 for me.
[quoted text clipped - 17 lines]
> >
> > Thanks in advance for any help!
Doug Robbins - 06 Feb 2005 13:27 GMT
Are you sure that the duplicate formfields have a name in the first place?
If I insert a formfield Text1, then copy and paste it into another place in
the document, the pasted formfield does not have a name.

See the article "How to assign a Name to a FormField that doesn't already
have a Name, using VBA" at:

http://word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Thanks and sorry about not elaborating, but here is the code I'm using:
>
[quoted text clipped - 69 lines]
>> >
>> > Thanks in advance for any help!
skbrown14 - 06 Feb 2005 16:21 GMT
Thanks, that worked.  I actually ran into some problems to begin with but
found out that I was trying to name the formfield with a space in it.  Once I
found that and used Trim to take off spaces, the
Dialogs(wdDialogFormFieldOptions).Execute worked great.  

Thanks alot!

> Are you sure that the duplicate formfields have a name in the first place?
> If I insert a formfield Text1, then copy and paste it into another place in
[quoted text clipped - 78 lines]
> >> >
> >> > Thanks in advance for any help!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.