views:

30

answers:

1

In Word 2003, I am trying to create a form that can generate additional entries if the person filling out the forms requires them and clicks a checkbox stating (for additional tables click here). I have tried a form field that runs a macro on entry but that does not seem to be working. Is there a more elegant way to make a form that can add a table in Word as the user requires?

Essentially something like this (as an unrelated though functionally accurate example):

http://pixiurl.com//image/5o2r751t%5FExample.png (Sorry I can't post images)

When the "Click here" is clicked is generates another exactly the same.

Also I need to make sure the fields on the new table remain blank even if they were filled in on the original so I can't use a copy and paste method.

Any help would be greatly appreciated.

A: 

create a document containing some text and a checkbox from the "Control Toolbox"; add a bookmark called "Here" at the position where you want to insert the table; add some more text.

Enter the following code for the control toolbox:

Private Sub CheckBox1_Click()
    If Me.CheckBox1 Then
        Selection.GoTo What:=wdGoToBookmark, Name:="Here"
        ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
        3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed
        With Selection.Tables(1)
            If .Style <> "Table Grid" Then
                .Style = "Table Grid"
            End If
            .ApplyStyleHeadingRows = True
            .ApplyStyleLastRow = True
            .ApplyStyleFirstColumn = True
            .ApplyStyleLastColumn = True
        End With
    Else
        Selection.GoTo What:=wdGoToBookmark, Name:="Here"
        With Selection.Tables(1)
            .Delete
        End With
    End If
End Sub

If the form is locked you may need to surround the IF-ELSE-ENDIF by Unprotect/Protect statements

MikeD