Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Naming A FormField (Word 2003/sp2)

    I have a form with many many fields in it. These fields need to be renamed and other options set.
    The problem: I can't set the name if I use a string variable. If I simple write the name in quotes it works - but at that rate I might as well open up each field in word.
    <pre>Sub ReSetFieldsNew()
    Const Split = "_"
    Dim strGroupName As String
    Dim IntChoices As Integer
    Dim intCounter As Integer
    Dim strFieldName As String
    Dim rngDoc As Range

    strGroupName = InputBox("Enter QuestionName")
    IntChoices = Selection.FormFields.Count

    Set rngDoc = Selection.Range
    For intCounter = 1 To IntChoices
    strFieldName = strGroupName & Split & IntChoices & Split & intCounter
    Debug.Print strFieldName
    With Selection.FormFields(intCounter)
    .Name = strFieldName ' this doesn't work - however if I use "Fred_3_1" everything is good
    .EntryMacro = "RadioCheckBox"
    .ExitMacro = "RadioCheckBox"
    .CalculateOnExit = True
    Debug.Print .Name
    End With
    rngDoc.Select

    Next intCounter
    End Sub
    </pre>


    I'd sure appreciate another pair of eyes, to see what I'm missing.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Naming A FormField (Word 2003/sp2)

    It works without problems for me (Word 2003 SP2 too) <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

    Does the problem persist if you quit and restart Word?

  3. #3
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Naming A FormField (Word 2003/sp2)

    I'm wondering if I'm missing a reference?
    Attached Images Attached Images
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  4. #4
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Naming A FormField (Word 2003/sp2)

    Yes the problem persists and continues on both my desktop and laptop machines.
    Here's a snap of the error msg
    Attached Images Attached Images
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Naming A FormField (Word 2003/sp2)

    No, if you needed an extra reference, you'd have gotten a syntax error instead of a run-time error.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Naming A FormField (Word 2003/sp2)

    Earlier today, I tested in Word 2003, now in Word 2002. Again without problems.

    Could you attach a small dummy document with some form fields and the code (after verifying that the error still occurs in it)?

  7. #7
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Naming A FormField (Word 2003/sp2)

    Hey, in building my fake document I think I came partway.
    1) fails if the selected text is an entire cell.
    2) in my original document every field seems to have the same name. So they aren't bookmarked properly.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Naming A FormField (Word 2003/sp2)

    I think you're on to something. The code also fails if at least one of the form fields has no name. Duplicate names and blank names can easily occur if you copy and paste form fields.
    So
    a) Don't run the code on a single entirely selected cell.
    [img]/forums/images/smilies/cool.gif[/img] Make sure that all form fields have unique, non-blank names before running the code.
    Not easy if you want to make the code available to end users!

  9. #9
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Location
    Redcliff, Alberta, Canada
    Posts
    4,066
    Thanks
    2
    Thanked 5 Times in 5 Posts

    Re: Naming A FormField (Word 2003/sp2)

    So, I did wind up manually renaming fields. But at least I know why now.
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  10. #10
    Star Lounger
    Join Date
    Feb 2001
    Location
    Virginia Beach, Virginia, USA
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Naming A FormField (Word 2003/sp2)

    I have just come across this problem. Specifically [img]/forums/images/smilies/cool.gif[/img]

    So
    Once you have formfields in a document with non-unique names, can you ever use .name to assign a name of a formfield?
    If no this pretty much kills copy/paste of any range with fields in it.

    Also, does this problem exist for code created fields

    I am trying to make an form with section that can expand based on data entry. Working with out field names will require some serious rethinking

    thanks

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Naming A FormField (Word 2003/sp2)

    Yes, it's a nuisance. You cannot assign a name to a nameless form field in code, only interactively. You can, however, assign a name to a form field that you create in code:

    Dim strName As String
    strName = ...
    With ActiveDocument.FormFields.Add(Selection.Range, wdFieldFormTextInput)
    .Name = strName
    ...
    End With

  12. #12
    Star Lounger
    Join Date
    Feb 2001
    Location
    Virginia Beach, Virginia, USA
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Naming A FormField (Word 2003/sp2)

    piffle.
    I was hoping to use cut/paste to create my expanded data section. Creating the rather complex structure with code will be tedious.
    Either that or figure out how to do the whole thing without rely on names
    oh well. I guess that's why I get the big bucks...

    Thanks for the prompt response

  13. #13
    Star Lounger
    Join Date
    Feb 2001
    Location
    Virginia Beach, Virginia, USA
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Naming A FormField (Word 2003/sp2)

    or I could cut/paste the structure then add the FormFields...
    just a bit slow sometimes
    shesh

  14. #14
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Naming A FormField (Word 2003/sp2)

    You could copy the range, then rename the existing fields to unique names, then paste the materials containing the original names. Actually, does that work? I suppose it depends on whether Word is storing a copy of the original or a pointer to the original...

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Naming A FormField (Word 2003/sp2)

    Problem is that if you copy/paste a form field, the copy is nameless, since you can't have two bookmarks with the same name. It would have been nice if Microsoft assigned a name with a sequential number, as it does when you copy/paste controls from the Control Toolbox (a copy of txtInvoice becomes txtInvoice1, then txtInvoice2 etc.), but unfortunately that is not the case.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •