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.
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
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.
Leroy
Laura,
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?
Thanks, Leroy
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.
Laura
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.
Would it be possible for me to send you a copy of my macro-enabled Word document?