Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-14-2015, 05:32 AM
tejaspareek tejaspareek is offline Automatically adding new rows based on form field Windows 7 64bit Automatically adding new rows based on form field Office 2010 64bit
Novice
Automatically adding new rows based on form field
 
Join Date: Oct 2014
Posts: 13
tejaspareek is on a distinguished road
Default Automatically adding new rows based on form field

Hi,



I am trying to create a form field document which displays a price of a product which is to be paid in a certain number of installments.

I want to automate the number of rows to be added automatically along with the form field options in it.

For eg: if there are 24 installments, 24 new rows are to be added below with the given form field options.

Need help from the experts as i tried some codes but they are not working. And i am not that good with word VBA.

Attached is the sample file containing the field where the number of installments are to be added and the form fields that are to be added to the new installment rows.

Thank you in advance.
Attached Files
File Type: docx Installment.docx (24.0 KB, 12 views)
Reply With Quote
  #2  
Old 04-14-2015, 07:44 AM
gmaxey gmaxey is offline Automatically adding new rows based on form field Windows 7 32bit Automatically adding new rows based on form field Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
Attached Files
File Type: docm Installment.docm (35.1 KB, 15 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 04-17-2015, 04:49 AM
tejaspareek tejaspareek is offline Automatically adding new rows based on form field Windows 7 64bit Automatically adding new rows based on form field Office 2010 64bit
Novice
Automatically adding new rows based on form field
 
Join Date: Oct 2014
Posts: 13
tejaspareek is on a distinguished road
Default Thank you

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
Reply With Quote
  #4  
Old 04-17-2015, 05:16 AM
tejaspareek tejaspareek is offline Automatically adding new rows based on form field Windows 7 64bit Automatically adding new rows based on form field Office 2010 64bit
Novice
Automatically adding new rows based on form field
 
Join Date: Oct 2014
Posts: 13
tejaspareek is on a distinguished road
Default Solved

Ok, i checked at your table, and got the answer.



Thank you so much.
You made my life much simple.
Reply With Quote
  #5  
Old 04-17-2015, 05:35 AM
gmaxey gmaxey is offline Automatically adding new rows based on form field Windows 7 32bit Automatically adding new rows based on form field Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You're welcome. I'm sorry but I didn't see your follow on question until just now. I used a Seq field which I think you have figured out for yourself.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically adding new rows based on form field Form auto fill based on a different field value. stct Word 26 06-15-2019 04:08 PM
Automatically adding new rows based on form field 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:27 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft