Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 11-17-2016, 07:20 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default Expanding tables with calculating form fields?

Hi,

I figured out how to make calculating form fields using these instructions.

Now, I'm modifying a form I created to have expanding table rows using "Repeating Section Content Control" under the Developer tab in MS Word 2013.

I would like each expanded table row to have form fields that can be totaled.

Right now, the fields in the row have unique bookmarks that are used to calculated a total. If I expand the table row, the new fields don't have bookmarks.

Does anyone know if there's a way to make this work?
Reply With Quote
  #2  
Old 11-17-2016, 09:57 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,013
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

The link you supplied relates to formfields, which are entirely different from content controls. You need to be aware that calculation formfields are buggy when taking inputs from other calculating formfields.

To see how to do ta wide range of maths calculations in Word, check out my Microsoft Word Field Maths Tutorial, at:
http://windowssecrets.com/forums/sho...Maths-Tutorial
or:
http://www.gmayor.com/downloads.htm#Third_party

To see how to do about everything you might want to do with date calculations in Word, check out my Microsoft Word Date Calculation Tutorial, at:
http://windowssecrets.com/forums/sho...ation-Tutorial
or:
http://www.gmayor.com/downloads.htm#Third_party
Do read the document's introductory material.

As for adding table rows in a document using formfields, see:
http://www.msofficeforums.com/word-v...html#post38312
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 11-18-2016, 03:05 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Sweet. Thank you.
Before I dive into those links/tutorials...

I was using Legacy Forms controls.
I just replaced a lot of the drop downs and text fields with the current versions.
I didn't do that with the fields that have the calculations. I'm wondering, before I start messing with it any further, is there a way to have conditions so that if I select something from a drop-down menu, it'll populate other fields.

Here is the form I'm referring to
https://drive.google.com/open?id=0B9...zUtenBveEZoNE0
The form is protected but there's no password (just leave it blank).

Right now I have it set up where I put the numbers in manually and it calculates the totals.
What I'd like to do is be able to select something from the drop-downs under Nomenclature and have it populate the Item N.E.W. field with a number. Then when I put in QTY, it'll calculate the TOTAL N.E.W.
Is that possible? Or am I asking too much of Word and should be doing this in something more dynamic like Acrobat? I did try this once as an Adobe form, but there are other pages that have functions that I don't think Acrobat offers like inserting photos.

I'm assuming the expanding tables option isn't possible, but ideally, I'd only like to have rows when I need them and not have a bunch of empties (clutter).
Reply With Quote
  #4  
Old 11-18-2016, 07:53 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,013
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

Quote:
Originally Posted by Father View Post
I'm wondering, before I start messing with it any further, is there a way to have conditions so that if I select something from a drop-down menu, it'll populate other fields.
See, for example:
http://www.msofficeforums.com/word/1...html#post46429
http://www.msofficeforums.com/word/2...html#post88302
http://www.msofficeforums.com/word/2...html#post74823
You might also be interested in the formfield conditional formatting solution in:
http://www.msofficeforums.com/word-v...html#post47254
Quote:
Originally Posted by Father View Post
I'm assuming the expanding tables option isn't possible, but ideally, I'd only like to have rows when I need them and not have a bunch of empties (clutter).
I've already provided you with a link for that.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 11-19-2016, 02:08 AM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
See, for example:
You might also be interested in the formfield conditional formatting solution in:
...
I've already provided you with a link for that.
Sweet. I"ll be checking it out all. Thank you so much!!!
Reply With Quote
  #6  
Old 11-21-2016, 07:35 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Crap... so I should have stuck with Form Fields rather than convert everything to Content Controls.

One of the reasons I thought using the content controls would be better is that for drop downs it still allows you to enter other words into the field. Can normal form fields do this as well?

I also did it because some of the information I was putting in normal form fields was getting cut short. That might have been more a result of the table cell size they were on and I was blaming the fields.

So you mentioned that form fields don't work well with content controls. Is that in general terms on or only when you're trying to relate/connect one type with the other?

For my sample, if I use form fields for the calculating fields but left the control control fields for the static information in other parts of form, will it cause problems?

Quote:
Originally Posted by macropod View Post
As for adding table rows in a document using formfields, see:
http://www.msofficeforums.com/word-vba/13955-macro-add-row-table-word-form.html#post38312
Macros scare the heck out of me... because I'm just not that familiar with coding. But I was able to remove the comments so that each new table has a specific numbered bookmark. VERY NICE!!!
Reply With Quote
  #7  
Old 11-21-2016, 08:36 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,013
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

Quote:
Originally Posted by Father View Post
Crap... so I should have stuck with Form Fields rather than convert everything to Content Controls.

One of the reasons I thought using the content controls would be better is that for drop downs it still allows you to enter other words into the field. Can normal form fields do this as well?
That is not possible with dropdown content controls; only with combobox content controls. There are ways of simulating this with a dropdown formfield (there is no combobox formfield) - but that, too, requires a macro.
Quote:
Originally Posted by Father View Post
I also did it because some of the information I was putting in normal form fields was getting cut short. That might have been more a result of the table cell size they were on and I was blaming the fields.
Probably.
Quote:
Originally Posted by Father View Post
So you mentioned that form fields don't work well with content controls. Is that in general terms on or only when you're trying to relate/connect one type with the other?
It's in general terms, but especially when checkboxes are involved or you're trying to tab from formfields to content controls then back to formfields again.
Quote:
Originally Posted by Father View Post
For my sample, if I use form fields for the calculating fields but left the control control fields for the static information in other parts of form, will it cause problems?
Possibly.
Quote:
Originally Posted by Father View Post
Macros scare the heck out of me... because I'm just not that familiar with coding. But I was able to remove the comments so that each new table has a specific numbered bookmark. VERY NICE!!!
I don't understand what you mean about removing comments - there is no need to remove comments from the macro code. They are never executed; they just explain things. They also have no connection with table bookmarks.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #8  
Old 11-21-2016, 09:14 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
I don't understand what you mean about removing comments - there is no need to remove comments from the macro code. They are never executed; they just explain things. They also have no connection with table bookmarks.
I was referring to:
' If you need the formfields named, activate the commented-out code.
Perhaps I didn't use the right terms. I did that for:
'For Each FmFld In .FormFields
'StrNms = StrNms & "|" & Left(FmFld.Name, Len(FmFld.Name) - 2) & Format(i, "00")
'Next
and
'.Select
'With Dialogs(wdDialogFormFieldOptions)
'.Name = Split(StrNms, "|")(i)
'.Execute
'End With

Right now I'm doing the stuff in the DropDownDemo.doc. It's pretty labor intensive.

So, when using that, whatever number I have set to a certain drop-down, can that number be used for a calculation?
Reply With Quote
  #9  
Old 11-21-2016, 10:03 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,013
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

Quote:
Originally Posted by macropod View Post
Right now I'm doing the stuff in the DropDownDemo.doc. It's pretty labor intensive.

So, when using that, whatever number I have set to a certain drop-down, can that number be used for a calculation?
Not only a number but text, too, can be used for the IF condition in a calculation.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #10  
Old 11-22-2016, 02:57 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Is there a way to make a text field {FORMTEXT} appear through an IF condition?
If I select "other" in a drop down, to allow an empty form field to appear to input a number.

For the calculations, I was originally using bookmarks for the field. With the drop down example the numbers generated from the IF condition don't have a bookmark associated with them. What do you put in place of a bookmark for expressions from those numbers?

For FormFields - Table Row Add.doc example - When I run this macro in another document with nested tables I get this error

Microsoft Visual Basic for Applications
"X Cannot access individual rows in this collection because the table has vertically merged cells."

The nested table doesn't have any merged cells so I'm not sure how to fix this.

Current version of form attached.
Attached Files
File Type: docm 2016 EOD Form Form Fields.docm (42.5 KB, 0 views)
Reply With Quote
  #11  
Old 11-22-2016, 03:22 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,013
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

Quote:
Originally Posted by Father View Post
Is there a way to make a text field {FORMTEXT} appear through an IF condition?
No. A macro would be required for that. See: https://social.technet.microsoft.com...lay?forum=word

Alternatively, to simulate a combobox, you could provide an option in the dropdown for 'free text' and use an on-exit macro macro with an Inputbox to insert the user’s 'free text' into the dropdown formfield. For example, suppose you have formfield “Dropdown1” with 5 items, the last of which offers free text entry. Adding the following on-exit macro to the formfield will provide that:
Code:
Sub FreeText()
Dim StrNew As String
With ActiveDocument.FormFields("Dropdown1").DropDown
  If .Value = 5 Then
  StrNew = Trim(InputBox("Input your text", "Free text input"))
  If StrNew = vbNullString Then Exit Sub
    .ListEntries(5).Delete
    .ListEntries.Add StrNew
    .Value = 5
  End If
End With
End Sub
Quote:
Originally Posted by Father View Post
For the calculations, I was originally using bookmarks for the field. With the drop down example the numbers generated from the IF condition don't have a bookmark associated with them. What do you put in place of a bookmark for expressions from those numbers?
When you insert a dropdown formfield into a document, Word gives it a default bookmark name (e.g. Dropdown1). You can see that when you examine the formfield's properties; you can also delete it or change it to something else.
Quote:
Originally Posted by Father View Post
For FormFields - Table Row Add.doc example - When I run this macro in another document with nested tables I get this error

Microsoft Visual Basic for Applications
"X Cannot access individual rows in this collection because the table has vertically merged cells."

The nested table doesn't have any merged cells so I'm not sure how to fix this.
Your table does have vertically merged cells. See item 8. Furthermore, the macro isn't designed to work with nested tables, so I don't know how you'll get along with that.

PS: It would be preferred for you to attach files here, rather than linking to them on another site. You can do that via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #12  
Old 11-22-2016, 06:45 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
When you insert a dropdown formfield into a document, Word gives it a default bookmark name (e.g. Dropdown1). You can see that when you examine the formfield's properties; you can also delete it or change it to something else.
I'm talking about this:
Dept = { FORMDROPDOWN }
{IF{REF Dropdown1 \* MERGEFORMAT}= "HR" "001"}
When the number, in this case 001, is generated by the IF condition, how do you use that number in a calculation/formula? The "001" has no bookmark to use in another formula. What would be the reference?

I tried just using the same formula and adding the calculation into it
{={IF{REF Dropdown1 \* MERGEFORMAT}= "HR" "001"}*(REF UXOQTY1}} but it doesn't work.

In my form I want the N.E.W. (from the selection made in Dropdown UXONomen01) * UXOQTY1 to be calculated and shown in the TOTAL N.E.W.
Since the TOTAL N.E.W. textfield relies on bookmarks to do a calculation (right?), I'm guessing it would have to be done outside of the field's properties.

I'm not sure how else to explain what I'm trying to do here.

Quote:
Originally Posted by macropod View Post
Your table does have vertically merged cells. See item 8. Furthermore, the macro isn't designed to work with nested tables, so I don't know how you'll get along with that.
Using this I put the sample into a vertically and horizontally merged table an it still works. Not sure what the difference is between what I'm doing with the sample and my working form.
Reply With Quote
  #13  
Old 11-22-2016, 10:20 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 15,013
macropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to allmacropod is a name known to all
Default

The form in post #10 doesn't include a Dropdown with a bookmark named Dropdown1, or one with either an "HR" or "001" option, so it's difficult to know exactly what you're doing. That said, the calculation field you refer to would be expressed as:
{IF{REF Dropdown1}= "HR" {REF UXOQTY1}}
as there is no multiplication required.

PS: I note that, despite my advice against it, your form contains both content controls and formfields.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #14  
Old 11-23-2016, 12:00 AM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The form in post #10 doesn't include a Dropdown with a bookmark named Dropdown1, or one with either an "HR" or "001" option, so it's difficult to know exactly what you're doing. That said, the calculation field you refer to would be expressed as:
{IF{REF Dropdown1}= "HR" {REF UXOQTY1}}
as there is no multiplication required.
My bad. This one is the one I was referring to.


Quote:
PS: I note that, despite my advice against it, your form contains both content controls and formfields.
I will take your advice... just haven't gotten to it with all the other stuff I don't know how to do.
Reply With Quote
  #15  
Old 11-23-2016, 02:56 PM
Father Father is offline Windows 7 32bit Office 2013
Novice
 
Join Date: Nov 2016
Posts: 27
Father is on a distinguished road
Default

I'm trying to do a similar condition formula where it displays coordinates.
It's not showing them right though.
In the formula it's written "842'59.8"N 16743'07.9"E"
It's displayed as N923'33.7NN
Is there a way to force it to show something exactly how it's written in the code?
Reply With Quote
Reply

Tags
calculating values, expanding table, form fields
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
Tables with form fields step10 Word 18 11-12-2013 02:27 PM
Enable editing in expanding fields marweste Word 11 10-21-2013 07:41 AM
How to prevent Tables from expanding HappyFingers Word 1 11-29-2010 01:54 PM
Calculating Form Fields in Microsoft Word wubba80 Word 1 06-25-2010 12:42 AM


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


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft