Law Office Solution
Register Now Forgot Password?  
Advanced Search  
icon Ms-Word
icon Ms-Excel
icon Ms-PowerPoint
icon Ms-Outlook
icon Miscellaneous
icon Adobe Acrobat
icon Windows
  Forum Register
  Forum Sign In
  Forum Home
Thread : Text Field Processing
From : lchen
To : All

Hi Laura,

I have a follow-up question from your 'Calculating in Forms' video.

I need to add a delimiter around user's input. For example, putting quotes or asterisks around whatever the users enter. Using your video as an example, I would like input of Jane Doe to become output of *Jane Doe*.

Is this something that can be done with the confine of the 'Text Form Field Options' dialogue box?

Thanks in advance.


Posted by : lchen Posted Date : Apr 16, 2013 Viewed : 141045
From : Laura Leader
Apr 16, 2013   10:38 PM
To : lchen
(1 of 8)
28.2 in reply to 28.1

Hi Ichen,

I don't know of any way to do this by just setting up the field. But you can do it with an exit macro. You can put the macro in the form. 

I would save the form as a macro enabled template, but you could also do it as a macro enabled document. Let me know if you need to know how to do that. Then:

1. Copy all the text below EXCEPT the first "Sub..." and last "End sub" lines. 
(So everything between those lines)

2. Make sure the form is currently NOT protected.

3. Choose Developer, Macros. The macros dialog box opens.

4. Type a name for the macro in the MacroName field.  
I used ReformatFieldText in my example below.

5. Set the "Macros In" pull down to your template/document name.

6. Click CREATE. This creates an empty macro and puts your cursor in it.

7. Paste the text you copied at the insertion point.
Your macro is created.

Back in the body of the form, for each field that you want this to run for, go into the properties and set "ReformatFieldText" as the exit macro.  When someone leaves a field, if they typed text in it, it will replace it with the same text with and * on either side. 

You can change what text it puts by changing the macro below.

If you need something else, like maybe a macro to get all the text from all the fields and stuff them in a delimited string let me know. That would also require a macro. Hope this helps.

Laura Leader


Sub ReformatFieldText()
Dim sFldName As String
Dim sFldTxt As String
'make sure there is a bookmark around the current field
'(the bookmark is the field name)
If Selection.Bookmarks.Count > 0 Then
'get the field name
     sFldName = Selection.Bookmarks(1).Name
'get the text in that field   
    sFldTxt = ActiveDocument.FormFields(sFldName).Result
'put an asterisk on either side of it   
    If Len(sFldTxt) > 0 Then  
          sFldTxt = "*" & sFldTxt & "*"
'stuff the new text back into the field   
          ActiveDocument.FormFields(sFldName).Result = sFldTxt
     End If
End if

End Sub

Posted by : Laura Leader Posted Date : Apr 16, 2013
From : lchen
Apr 17, 2013   10:42 AM
To : Laura Leader
(2 of 8)
28.3 in reply to 28.2

Hi Laura,

Thank you so much for the instant reply.

And, best of all, it works!

I've scoured the Net for days, to no avail.

You are truly a life saver!

I'll be singing your praises to my friends and colleagues for a long while.





Posted by : lchen Posted Date : Apr 17, 2013
From : lchen
Apr 17, 2013   10:57 AM
To : Laura Leader
(3 of 8)
28.4 in reply to 28.2


I just noticed that the macro updates the user input with the concatenated string.

Would it be possible to only update the outgoing bookmark string value to the {REF...} field and leave the user input intact?



Posted by : lchen Posted Date : Apr 17, 2013
From : Laura Leader
Apr 17, 2013   8:19 PM
To : lchen
(4 of 8)
28.5 in reply to 28.4

Hi Leroy,

Glad it worked (well, mostly worked)!

Can you elaborate on exactly what you are trying to do?  A "ref" field is a field that refers to text in another field.  So there is no way to make the ref field say *text* if what it's referring to just says text.  But I am guessing you want the delimiters around the values for use somewhere else, not to show up in the form that was filled in. 

We'll probably have to use VBA but I suspect we can do what you want.  I just need a little more info on your final goal for the data.


Posted by : Laura Leader Posted Date : Apr 17, 2013
From : lchen
Apr 18, 2013   1:57 PM
To : Laura Leader
(5 of 8)
28.6 in reply to 28.5

I'm making a barcode generator template. As you may know barcode strings are delimited by '*'. I was hoping to sheild from the user the technical detail of having to surround an input string with *.  But this is purely interface cosmetics and I'm more than happy to settle with the interface as it is. The little macro completes it. Thanks again.

Posted by : lchen Posted Date : Apr 18, 2013
From : Laura Leader
Apr 18, 2013   4:12 PM
To : lchen
(6 of 8)
28.7 in reply to 28.6
Hi Leroy, Actually, I did not know that about bar codes! What I'm curious about is how you have been getting the data from the form fields to your barcode generator. Do you have a macro to do that? The macro I provided runs on each field as the user exits the field. But it would be just as easy to have a macro that runs later on all the fields. It would just need to be triggered somehow. which could be the save or close of the document, or you (or whoever) clicking a button to trigger it. Assuming you're using a macro to get the data out of the fields, it could be part of that macro. Laura
Posted by : Laura Leader Posted Date : Apr 18, 2013
From : lchen
Apr 29, 2013   6:39 PM
To : Laura Leader
(7 of 8)
28.8 in reply to 28.7

Would it be possible for me to send you a copy of my macro-enabled Word document?

Posted by : lchen Posted Date : Apr 29, 2013
From : Laura Leader
Apr 29, 2013   7:19 PM
To : lchen
(8 of 8)
28.9 in reply to 28.8
Sure, send it to Laura @ Lawofficesolution .com (without the spaces, of course). when you send it, tell me what macro you're using to get the data from the form now. Laura
Posted by : Laura Leader Posted Date : Apr 29, 2013
©2009 Law Office Solution - Terms - Privacy Policy