T
Tendresse
Hi all, i'm not sure what i'm doing wrong here and need some help please.
I wrote a macro (AddTable) to repeat (copy and paste) the table located
above the control button. Users can repeat the table as many times as they
like. I also wrote another macro (DelTable) to delete any of the above
tables. However, i don't want users to delete the very first table (I need at
least one table to be in the form).
In order to identify the first table (so that it doesn't get deleted), i
gave a name ("Client1") to the first Text Form Field in that table. The macro
that repeats the table, contains a line that changes that name for all the
new added tables.
This way, when users want to delete any of the tables, the 'Delete Macro'
will first check the name of the first Text Field, if it is "Client1" then
the table won't be deleted.
When i run the 'AddTable' macro, I get an error message: Compile Error,
Method or data member not found. This error seems to refer to the line that
renames the form field.
Here are both my codes AddTable and DelTable. Any ideas would be much
appreciated. I'm using word 2003.
Cheers, Tendresse
Sub AddTable()
' Select the table above the control button
Do
Selection.MoveUp wdLine, 1
Loop While Selection.Tables.Count = 0
' Copy and Paste Table
Selection.Tables(1).Select
Selection.Copy
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.Paste
' Rename the first text field in the new table
Do
Selection.MoveUp wdLine, 1
Loop While Selection.Tables.Count = 0
Dim myFields As FormFields
Set myFields = Selection.Tables(1).Range.FormFields
myFields(1).Select
' the next line is where the error happens
Selection.myFields(1).Name = "CanDelete"
' clear field contents in the new table
Dim i As Integer
For i = 1 To myFields.Count
Select Case myFields(i).Type
Case wdFieldFormTextInput
myFields(i).Result = myFields(i).TextInput.Default
Case wdFieldFormCheckBox
myFields(i).CheckBox.Value = myFields(i).CheckBox.Default
Case wdFieldFormDropDown
myFields(i).DropDown.Value = myFields(i).DropDown.Default
End Select
Next i
End Sub
________________________________________
Sub DelTable()
' Select table above control button
Do
Selection.MoveUp wdLine, 1
Loop While Selection.Tables.Count = 0
Dim myFields As FormFields
Set myFields = Selection.Tables(1).Range.FormFields
myFields(1).Select
If myFields(1).Name = "Client1" Then
MsgBox ("Sorry, you cannot delete this table")
Exit Sub
Else
Selection.Tables(1).Delete
Selection.TypeBackspace
End If
End Sub
I wrote a macro (AddTable) to repeat (copy and paste) the table located
above the control button. Users can repeat the table as many times as they
like. I also wrote another macro (DelTable) to delete any of the above
tables. However, i don't want users to delete the very first table (I need at
least one table to be in the form).
In order to identify the first table (so that it doesn't get deleted), i
gave a name ("Client1") to the first Text Form Field in that table. The macro
that repeats the table, contains a line that changes that name for all the
new added tables.
This way, when users want to delete any of the tables, the 'Delete Macro'
will first check the name of the first Text Field, if it is "Client1" then
the table won't be deleted.
When i run the 'AddTable' macro, I get an error message: Compile Error,
Method or data member not found. This error seems to refer to the line that
renames the form field.
Here are both my codes AddTable and DelTable. Any ideas would be much
appreciated. I'm using word 2003.
Cheers, Tendresse
Sub AddTable()
' Select the table above the control button
Do
Selection.MoveUp wdLine, 1
Loop While Selection.Tables.Count = 0
' Copy and Paste Table
Selection.Tables(1).Select
Selection.Copy
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeParagraph
Selection.Paste
' Rename the first text field in the new table
Do
Selection.MoveUp wdLine, 1
Loop While Selection.Tables.Count = 0
Dim myFields As FormFields
Set myFields = Selection.Tables(1).Range.FormFields
myFields(1).Select
' the next line is where the error happens
Selection.myFields(1).Name = "CanDelete"
' clear field contents in the new table
Dim i As Integer
For i = 1 To myFields.Count
Select Case myFields(i).Type
Case wdFieldFormTextInput
myFields(i).Result = myFields(i).TextInput.Default
Case wdFieldFormCheckBox
myFields(i).CheckBox.Value = myFields(i).CheckBox.Default
Case wdFieldFormDropDown
myFields(i).DropDown.Value = myFields(i).DropDown.Default
End Select
Next i
End Sub
________________________________________
Sub DelTable()
' Select table above control button
Do
Selection.MoveUp wdLine, 1
Loop While Selection.Tables.Count = 0
Dim myFields As FormFields
Set myFields = Selection.Tables(1).Range.FormFields
myFields(1).Select
If myFields(1).Name = "Client1" Then
MsgBox ("Sorry, you cannot delete this table")
Exit Sub
Else
Selection.Tables(1).Delete
Selection.TypeBackspace
End If
End Sub