• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 79
  • Last Modified:

Automatically spell out any Euro amount entered as a digit in a field for Word.

I have posted a similar question before here, but didn't get to solving it, so here is my current problem: I have a word document for evaluations of art pieces with descriptions and fields, and a macro that inserts an auto text when entering one of these fields (It just inserts more descriptions and fields at the bottom, so I can keep going when i am at the bottom of a page) That all works perfectly fine. Now, the only thing I did not get to work is this: I have an amount that is different for each different art piece, then I have a field (for now) in which I have to type the amount spelled out (so, for example: $40.00, forty USD) I am looking for a way to create the spelled amount automatically after I have populated the field with the digit amount. I know Eric and Graham have given some good suggestions in my previous question, but since I have changed the document completely, and I wasn’t able to re-create what they did, I wanted to ask again for help in here. I have attached the file, so you can see what I have right now but for the macro. Thanks a lot in advance (and I work on Word for Mac 2011).
0
mvp1985
Asked:
mvp1985
  • 6
  • 4
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
Follow your numerical FormField with a Ref field with the bookmark name of the numerical field - visible in Properties from the right-click context menu. Tick the 'Calculate on Exit' checkbox to make sure that the REF field gets updated:

{ REF Text3 \*CardText }
0
 
Eric FletcherCommented:
I posted the following annotated screen shots in response to your older question before I noticed you'd started a new one. My example shows how the field codes do the work, but use Graham's procedure to set this up in your form. (edited: my example uses the bookmark name thisArtValue for the numeric value, whereas Graham's example used a bookmark named Text3 for the same referenced value.)Annotated examples from template showing field codes and resultsThe Language attribute in effect for the text containing the Cardtext field code switch determines which language to use for the calculated field code's result (here it is German).
0
 
mvp1985Author Commented:
Thanks Graham and especially Eric for the help and the diagram, this is very helpful. Now it just has one flaw: It works exactly like I want it, but only without the macro. With the macro (that runs on the entry of the field at the very bottom of the page) I run into the following problem:
The location of the bookmarks get copied too, and that means that the point 5 in your diagram on a newly create page that also contains the fields does not match point 4, but point 4 from the page above.
In oder for you to be able to recreate this issue here is the macro: (thanks Graham, I believe you have helped me with this last time)

Sub Macro3a()
   Dim aDoc As Document
   Dim strPassword As String
   strPassword = ""
   Set aDoc = ActiveDocument
   If aDoc.ProtectionType <> wdNoProtection Then
       aDoc.Unprotect strPassword
   End If
   Application.Templates(aDoc.AttachedTemplate.FullName). _
       BuildingBlockEntries("AASKurz").Insert Where:=aDoc.Bookmarks("\EndOfDoc").Range
   aDoc.Protect Type:=wdAllowOnlyFormFields, Password:=strPassword
End Sub

I created the “BuildingBlockEntry" by creating an Autotext with the name “AASKurz” that is just a copy of the template I posted before.

What this does is just adding a page where I can add two more art evaluations.

Thanks again for your feedback and help.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Eric FletcherCommented:
I'm a bit rusty on using Word forms, so perhaps Graham will have a better idea about how to manage this within the code related to the form.

Note that if a single form will include 2 art evaluations, you'll need to have two separate bookmarked values to be able to differentiate between them in the REF fields. The SEQ fields will calculate to 1 and 2 properly on a single page, but the macro would need to be able to reset the initial value if it is used to create more evaluations on the same day (i.e. the first two would be 001 and 002, but the next ones would need to be 003 and 004, etc.).
0
 
mvp1985Author Commented:
Hey Erich, I already included the two separate bookmarked values in my template, and you are completely right about the requirements of the macro.... This is what I need.
0
 
GrahamSkanRetiredCommented:
You will need to update the bookmark name of the 'Value:' form field and also the new REF field .
Sub Macro3a()
   Dim aDoc As Document
   Dim strPassword As String
   Dim strRefFieldText As String
   Dim strRefFieldParts() As String
   Dim iNumber As Integer
   strPassword = ""
   Set aDoc = ActiveDocument
   If aDoc.ProtectionType <> wdNoProtection Then
       aDoc.Unprotect strPassword
   End If
   'get the text of current last field e.g. REF FFValue_01
   strRefFieldText = aDoc.Fields(aDoc.Fields.Count).Code.Text
   
   Application.Templates(aDoc.AttachedTemplate.FullName). _
       BuildingBlockEntries("AASKurz").Insert Where:=aDoc.Bookmarks("\EndOfDoc").Range
       
       'increment the number and update the new last field
       strRefFieldParts = Split(strRefFieldText, "_")
       iNumber = Val(strRefFieldParts(1)) + 1
       strRefFieldParts(1) = Format(iNumber, "00")
       strRefFieldText = Join(strRefFieldParts, "_")
       aDoc.Fields(aDoc.Fields.Count).Code.Text = strRefFieldText
       
       'extract the name for the new last form field
       strRefFieldParts = Split(strRefFieldText, " ")
       aDoc.FormFields(aDoc.FormFields.Count).Name = strRefFieldParts(1)
       
   aDoc.Protect Type:=wdAllowOnlyFormFields, Password:=strPassword
End Sub

Open in new window

0
 
mvp1985Author Commented:
Now I get the run-time error 5941. What is that about? Also, one thing I noticed, the macro only includes the first bookmark, not the second. I have two bookmarks assigned, since I have two positions per page, and with the macro I want to create a new page with two positions.
0
 
GrahamSkanRetiredCommented:
Sorry. I missed the notification for your last comment.

What is the text message for the error and on which code line does it occur?
For a second bookmark, the code would have to be repeated with a different name.
0
 
mvp1985Author Commented:
See attached file for error message.
0
 
mvp1985Author Commented:
See attached file for error message.
1.pdf
0
 
GrahamSkanRetiredCommented:
For the sake of text searches, the error message is:

Run-time '5941':
The requested member of the collection does not exist.

There are two collections referenced in the code, Fields and BuildingBlockEntries. So either there are no fields in the document, or the BuildingBlockEntry  "AASKurz"  is missing.

Which line does it fail on?
0
 
mvp1985Author Commented:
Graham, you are absolutley right. This was the issue. Thanks a lot for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now