Results 1 to 13 of 13
  1. #1
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    autotext in a form (word 2003)

    I'm wondering if it's possible in a form to have autotext drop into a document if someone clicks on a check box or selects yes from a multi answer box. i tried to do this by attaching a macro, but the response when attempted is that this is protected do you want to debug? i know nothing about debugging. what i want is if i click a button, autotext will appear on the next line.
    thanks for any help.

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

    Re: autotext in a form (word 2003)

    You cannot insert AutoText into a document protected for forms, so your macro will have to unprotect the document, insert the AutoText entry, then protect the document. Something like this:

    ActiveDocument.Unprotect
    ActiveDocument.FormFields("chkBox").Range.Select
    Selection.MoveDown
    ActiveDocument.AttachedTemplate.AutoTextEntries("B lah").Insert Selection.Range
    ActiveDocument.Protect wdAllowOnlyFormFields, True

  3. #3
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: autotext in a form (word 2003)

    thanks Hans, I'll give this a try.

  4. #4
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: autotext in a form (word 2003)

    Thanks Hans, I've been playing around with this and have had some success. i've attached a template and you'll see my amateurish attempts have led me to Example D which seems close to the mark, but with one step still needed ie merging the drop down row into only one cell instead of whatever number of cells were in the row preceding it. if you have any solutions it will be most appreciated.
    Attached Files Attached Files

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

    Re: autotext in a form (word 2003)

    Try this version:

    Sub drop2()
    ' Test whether the check box has been ticked
    If ActiveDocument.FormFields("Check15").CheckBox.Valu e = True Then
    ActiveDocument.Unprotect
    Selection.InsertRowsBelow 1
    ' Merge the cells in the inserted row
    Selection.Cells.Merge
    ActiveDocument.FormFields("Check15").Range.Select
    Selection.MoveDown
    ActiveDocument.AttachedTemplate.AutoTextEntries("B lah").Insert Selection.Range
    Selection.MoveUp Unit:=wdLine, Count:=1
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    End Sub

  6. #6
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: autotext in a form (word 2003)

    Thanks Hans, I tried that macro and it did merge the cells, however it didn't seem to place the cursor in the field (Example F). example G shows my utter failure to provide a similar macro to a multiple choice drop down form field, where i want the macro only to run if the response is yes.
    thanks again
    Attached Files Attached Files

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

    Re: autotext in a form (word 2003)

    Try these versions:

    Sub exampleedrop()
    If ActiveDocument.FormFields("Check17").CheckBox.Valu e = True Then
    ActiveDocument.Unprotect
    Selection.InsertRowsBelow 1
    ' Merge the cells in the inserted row
    Selection.Cells.Merge
    Selection.Collapse
    ActiveDocument.AttachedTemplate.AutoTextEntries("B lah").Insert Selection.Range
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=True
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    End Sub

    Sub dropdowntest()
    If ActiveDocument.FormFields("Dropdown2").DropDown.Va lue = 1 Then
    ActiveDocument.Unprotect
    Selection.InsertRowsBelow 1
    ' Merge the cells in the inserted row
    Selection.Cells.Merge
    Selection.Collapse
    ActiveDocument.AttachedTemplate.AutoTextEntries("B lah").Insert Selection.Range
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=True
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    End Sub

  8. #8
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: autotext in a form (word 2003)

    thanks Hans, they both worked and then i refined them to this
    If ActiveDocument.FormFields("Dropdown6").DropDown.Va lue = 1 Then
    ActiveDocument.Unprotect
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.SplitTable
    Application.DisplayAutoCompleteTips = True
    ActiveDocument.AttachedTemplate.AutoTextEntries("c hangelinks").Insert _
    Where:=Selection.Range, RichText:=True
    Selection.TypeBackspace
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.MoveUp Unit:=wdLine, Count:=2
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    End If
    there's probably some needless commands in there repairing my poor typing, but I'm sure you get the drift. One last question. suppose someone triggers that macro and then realises they should not have done that. Given that the form has relocked itself, is there a way or a macro they could run to undo the last macro?
    thanks again.

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

    Re: autotext in a form (word 2003)

    You could provide a custom toolbar button with caption "Delete Row". When clicked, it deletes the row that contains the currently active form field. The toolbar button would run a macro like this:

    Sub DeleteRow()
    If Selection.Information(wdWithInTable) Then
    If MsgBox("You are about to delete a row. Are you sure?", _
    vbQuestion + vbYesNo) = vbYes Then
    ActiveDocument.Unprotect
    Selection.Cells.Delete wdDeleteCellsEntireRow
    ActiveDocument.Protect wdAllowOnlyFormFields, True
    Else
    Beep
    End If
    End If
    End Sub

    (Personally, I would also use a custom toolbar button "Insert Row" to insert a row instead of dropdowns or check boxes.)

  10. #10
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: autotext in a form (word 2003)

    Perhaps I spoke a little too soon. I had been presuming that DropDown.Value = 1 equated to if Yes was selected the macro worked, if no was selected the macro was ignored and the cursor tabbed to the next field, however it seems that the macro works no matter what response is selected. When i replace 1 with Yes, the macro does not seem to work at all - i tried the variation of "Yes", but no luck there either.
    See what happens when you let a kid in an adult playground.
    Again, any help most appreciated.

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

    Re: autotext in a form (word 2003)

    Dropdown.Value returns the index of the selected item: 1 = first item, 2 = second item etc.
    When I copy the code from your previous reply into the template and adjust the name of the autotext entry and of the dropdown, the code is only executed when I select Yes (the first item), no when I select No (the second item).

  12. #12
    Lounger
    Join Date
    Sep 2001
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: autotext in a form (word 2003)

    thanks Hans, it does work, i just incorrectly referenced bookmark1instead of dropdown1. My next problem is slightly different. I can't get the table in the attached zip file to be accepted as autotext. It will accept up to row 5 but if i include row 6 on it will not accept and returns a blank preview and no option to add.
    thanks for all your help. I'm also going to post this as a separate problem.
    Attached Files Attached Files

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

    Re: autotext in a form (word 2003)

    Since you posted this in a new thread too, I will lock this one now, to prevent duplication.

    Please post all replies in the thread starting at <post:=671,032>post 671,032</post:>.

Posting Permissions

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