Results 1 to 15 of 15
  1. #1
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word 2003 template: Insert new formatted row (Word 2003)

    I have a fillable form (Word 2003 template with VBA code) for users to fill out. At the end of the table, the user is prompted to add a new row. The format is copied to the new row, but, unfortunately, so is the data from the previous row. Ideally, Id like only the format to be copied to the new row (not the data) so users can insert new data. Is this possible? (I could not upload the template with VBA code, so I've copied it to the document file. I hope this works.)
    Attached Files Attached Files

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

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    You could create an AutoText entry in the template consisting of a table row with blank formfields, and insert that below the table.

    Or you could insert the following lines after pasting the row and before reprotecting the document:
    <code>
    Selection.MoveUp Unit:=wdLine
    Dim ff As FormField
    For Each ff In Selection.Rows(1).Range.FormFields
    ff.Result = ""
    Next ff</code>

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

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    By the way, if you'd like to attach a template to a future post, you can zip it and attach the zip file.

  4. #4
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    This worked like a charm. You've helped me once again--thanks.

  5. #5
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    I inserted the code you sent. This worked for all fields except dropdown fields. When a line was inserted in a table with a dropdown field, the value in the dropdown field carried onto the new line. Thereafter, values from previous line were copied into remaining fields. Is there a way around this?
    Attached Files Attached Files

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

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    You can use this version, it will also handle check boxes from the Forms toolbar.

    For Each ff In Selection.Rows(1).Range.FormFields
    Select Case ff.Type
    Case wdFieldFormTextInput
    ff.Result = ""
    Case wdFieldFormDropDown
    ff.DropDown.Value = 1
    Case wdFieldFormCheckBox
    ff.CheckBox.Value = False
    End Select
    Next ff

  7. #7
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    Bingo! Thanks so much for your help.

  8. #8
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    Thanks for providing a solution to my problem of adding a formatted row to the table in my form--and for having the foresight to include checkboxes. I actually did alter the form to include checkboxes. I've got the routine running when the No box is reached. Is this correct? Also, after the row is added, the cursor skips to the second column. Ideally, it should be in the first column. Could you please help fix this?
    Attached Files Attached Files

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

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    I'd say you need just a single check box, to be ticked if the checklist for that row has been completed.

    You can set focus to the first text box in the new row by inserting the line

    Selection.HomeKey Unit:=wdRow

    below the line

    Selection.MoveUp Unit:=wdLine

  10. #10
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    Thanks, Hans. I added the line as you suggested, and it worked in the table I sent you. I still have one lingering problem in another table (see attached file). After the new line is inserted, the cursor does not go to the first cell in the newly added line. This feature works in all the other tables in my form, so I'm puzzled. Do you have any idea why? I'm sending only a portion of the template--the one that's acting up. I could send the entire template if necessary. As always, I appreciate your help. This project is almost done, thanks to you!
    Attached Files Attached Files

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

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    I have no explanation for this behavior, but I think the table has become corrupt in some strange way. If I copy the table and the macro into a new document, the insertion point doesn't go to the first cell in the new row, but if I create a new table and use the same macro, it works correctly. So I would recommend you to delete the table and create it again from scratch.

  12. #12
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    Thanks, I'll definitely follow your suggestion.

  13. #13
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    Thank you, your solution worked! I was just asked to change the form, and a new problem arose! The row that is added after I respond to the prompt "Add a new row?" is not centered vertically on the line like the preceding row. I've looked everywhere, and I have rebuilt the table, but I cannot figure out why this is happening. This is the only place in the form where this problem occurs. Do you have any suggestions?
    Attached Files Attached Files

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

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    I have no idea why it happens, but you can correct it by inserting the line

    Selection.Rows(1).Cells.VerticalAlignment = wdCellAlignVerticalCenter

    immediately below the line

    Selection.HomeKey Unit:=wdRow

    in the AddRow macro.

  15. #15
    Lounger
    Join Date
    May 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2003 template: Insert new formatted row (Word 2003)

    Once again, you solved my problem. Many thanks. With any luck, this form is final!

Posting Permissions

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