|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Mingle legacy fields and content controls so external program can insert data at bookmarks
A client management db passes information to my Word forms by way of Bookmarks thus all forms use legacy fields with approved identifiers in the 'Bookmark' property.
Now I need functionality that the legacy fields don't offer. Can I intermingle these older fields with content controls in the same form. Will tabbing work correctly? If not, can I somehow link a bookmark to a content control? |
#2
|
||||
|
||||
In very brief testing, it appears that the form fields are skipped over when there are CCs in the file. I've seen mvps and admins on this and other forums vaguely advise against intermingling CCs and legacy fields so that may be the reason that advise is provided. I have not yet seen other problems when this happens but if it can be avoided I would say you should stick with one or the other.
The method the Client Mgmt DB uses to populate the bookmarks is an unknown factor so if you can't manipulate it and it is critical to the document usage then I would probably stay exclusively with legacy fields. Or else you lose the 'tab into fields' functionality. You could conceivably use bookmarks inside a rich text CC but the bookmark would likely be destroyed if someone tabs into the CC and types. Conversely, putting the bookmark outside the CC would remove the CC when the DB updates the bookmark value. Either way there is a drawback that you should avoid if the DB is updating content as well as allowing users to tab across fields and possibly retype content.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
I wouldn't recommend using CCs and legacy form fields in the same document. They achieve the form functionality in different ways. Legacy form fields require the form to be protected for forms. CCs do not and as Andrew has suggested, do not provide the tabbed access when so protected.They provide that when Editors are applied and the document is protected as read only.
You can however bookmark the content control and you can lock the control against deletion. My CC Tools add-in Insert Content Control Add-In has a module to convert legacy form fields to rich text controls retaining the bookmark names (though the controls themselves are not bookmarked). The bookmarking can be achieved easily enough with a simple macro. (Macro1 below). You can then use the option to add editors and protect the form. Test the outcome with Macro2. This will write the same value to all the controls. If you are happy with the result, you can clear the test values with macro3. You will need the form password, if any, to convert form fields to content controls. Frankly content controls are rather more robust than legacy form fields and if your third party application will work with them when bookrmarked (if it just writes to named bookmarks, it almost certainly should) that would be the way to go. I suggest you experiment with a copy of the form. Code:
Sub Macro1() Dim oCC As ContentControl For Each oCC In ActiveDocument.ContentControls oCC.Range.Bookmarks.Add oCC.Title Next oCC Set oCC = Nothing End Sub Sub Macro2() Dim i As Integer Dim sName As String Dim oBM As Bookmark For i = 1 To ActiveDocument.Bookmarks.Count sName = ActiveDocument.Bookmarks(i).Name FillBM sName, "This is a test" Next i End Sub Sub Macro3() Dim oCC As ContentControl For Each oCC In ActiveDocument.ContentControls oCC.Range.Text = "" Next oCC Set oCC = Nothing End Sub Public Sub FillBM(strbmName As String, strValue As String) 'Graham Mayor - https://www.gmayor.com Dim oRng As Range With ActiveDocument On Error GoTo lbl_Exit If .Bookmarks.Exists(strbmName) = True Then Set oRng = .Bookmarks(strbmName).Range oRng.Text = strValue oRng.Bookmarks.Add strbmName End If End With lbl_Exit: Set oRng = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
|||
|
|||
Thank you, GMayor. If I understand your macro 1 correctly, your naming the bookmark with the title of the control. Since my external source is looking for specific bookmark names then I would Title the control with those specific keywords. Yes?
|
#5
|
||||
|
||||
If you use the add-in to convert form fields to content controls, the content controls will be titled with the bookmark names from the form fields. The add-in will allow you to page through the controls and change any titles if required.
The macro simply adds the bookmarks to the content controls using the same names as the content control titles. Content controls are not otherwise bookmarked and thus would not be seen by your external source.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#6
|
|||
|
|||
Thank for all of this but it seems my external source cannot pass data to the bookmarked content control. Bummer.
That said, I can pass data to hidden text fields in the document. Could I, with code, write the value of a hidden filed to a content control? |
#7
|
|||
|
|||
Legacy form fields are not required for there to be bookmarks.
You can add bookmarks to your document/template and these can be written to by an application. |
#8
|
|||
|
|||
Charles, It seems that would simply things. I'm testing and I don't see the data expected in the bookmark I added. I do see data in the Text form fields (legacy). Maybe I don't understand the technique.
|
#9
|
|||
|
|||
It sounds as if you need to talk with your application developer. For some reason they are looking for legacy formfields and identifying them by their bookmarks rather than simply inserting at a bookmark.
|
#10
|
|||
|
|||
I agree. I think they are looing for a field property instead of a bookmark. If that is true can I go back to idea of a hidden field? Could I write that value elsewhere?
|
#11
|
|||
|
|||
We do not have access to the code that is writing the data. You need to work with your application developers. They could write to:
A legacy formfield is not an ordinary Word field. (MS has a long practice of using confusing names.) You could insert a legacy formfield with the bookmark and format it as hidden using the font formatting dialog. How that would work I have no idea. |
Tags |
control, legacy |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
insert the 2 content controls into a Repeating Section in a table | smaccharoli | Word VBA | 2 | 02-27-2018 08:49 AM |
How to insert bookmarks for content or Text of ContentControl | lvganesh | Word VBA | 5 | 12-12-2017 11:27 PM |
How can I set up tab to go back and forth between legacy fields and content control fields in a Word | Ikajed | Word | 1 | 10-13-2017 06:06 PM |
Creating a Report Template / User Form and/or Content Controls with repetitive data throughout | 53bigdog | Word VBA | 1 | 04-05-2016 04:00 PM |
Insert image icons are showing up on images that have content controls but only on some computers. | mandylach | Word | 0 | 11-10-2014 07:44 PM |