![]() |
|
|
|
#1
|
|||
|
|||
|
Why are you mixing formfields and CCs. You can do this with CCs and a restricted form:
Code:
Select Case ContentControl.Title
Case "Installments"
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
Set oTbl = Selection.Tables(1)
For lngCount = oTbl.Rows.Count To 4 Step -1
oTbl.Rows.Last.Delete
Next lngCount
For lngCount = 2 To CLng(ContentControl.Range.Text)
oTbl.Rows.Last.Range.Copy
oTbl.Rows.Last.Range.Paste
Next lngCount
For lngCount = 1 To CLng(ContentControl.Range.Text)
If IsNumeric(oTbl.Rows(1).Cells(2).Range.ContentControls(1).Range.Text) Then
oTbl.Rows(lngCount + 2).Cells(2).Range.ContentControls(1).Range.Text = _
oTbl.Rows(1).Cells(2).Range.ContentControls(1).Range.Text / CLng(ContentControl.Range.Text)
Else
oTbl.Rows(lngCount + 2).Cells(2).Range.ContentControls(1).Range.Text = "$0.00"
End If
Next lngCount
oTbl.Range.Fields.Update
oTbl.Rows(3).Cells(2).Range.ContentControls(1).Range.Select
ActiveDocument.Protect wdAllowOnlyReading, True
End Select
End Sub
|
|
#2
|
|||
|
|||
|
Thank you Greg,
My 90% problem is solved. However, when i tried to impliment the code in my form sheet, i am facing an issue. The installment number in the table remains 1 for all the installment. The table that you created changed the number for all the installment, however, the same is not working in the document. I made some changes in the code while using it in my form, did i make any mistake in entering the code? Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim lngCount As Long
Dim oTbl As Word.Table
Select Case ContentControl.Title
Case "Installments"
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
Set oTbl = Bookmarks("Inst1").Range.Tables(1)
For lngCount = oTbl.Rows.Count To 5 Step -1
oTbl.Rows.Last.Delete
Next lngCount
For lngCount = 2 To CLng(ContentControl.Range.Text)
oTbl.Rows.Last.Range.Copy
oTbl.Rows.Last.Range.Paste
Next lngCount
For lngCount = 1 To CLng(ContentControl.Range.Text)
If IsNumeric(oTbl.Rows(2).Cells(2).Range.ContentControls(1).Range.Text) Then
oTbl.Rows(lngCount + 3).Cells(2).Range.ContentControls(1).Range.Text = _
oTbl.Rows(2).Cells(2).Range.ContentControls(1).Range.Text / CLng(ContentControl.Range.Text)
Else
oTbl.Rows(lngCount + 3).Cells(2).Range.ContentControls(1).Range.Text = "$0.00"
End If
Next lngCount
oTbl.Range.Fields.Update
oTbl.Rows(4).Cells(2).Range.ContentControls(1).Range.Select
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Select
End Sub
|
|
#3
|
|||
|
|||
|
Ok, i checked at your table, and got the answer.
![]() Thank you so much. You made my life much simple. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Form auto fill based on a different field value.
|
stct | Word | 31 | 05-02-2024 04:48 PM |
VBA to automatically sort items based on Mail Merge field
|
taylorblu | Word VBA | 3 | 09-08-2014 09:52 AM |
| MACRO - Insert row based on Form Field Criteria | Elan05 | Word VBA | 5 | 04-16-2013 06:39 AM |
| Is there a way to do this? (automatically enter text based on form data) | TIKKI555 | Word | 0 | 05-26-2010 09:21 AM |
| Form field to automatically be added to header? | razberri | Word VBA | 3 | 02-22-2010 03:48 PM |