Userform data to repeat multiple times RRS feed

  • Question

  • I have created a userform to integrate data into a contract.  Placing the fields into the .dotm via bookmarks is working, but when I try to repeat the text from the userform field further down the document I get nothing.  I'm guess that I'm doing everything incorrectly.  Can someone please tell me how to repeat data from a userform multiple times within a document?  For example:  on the userform, we will enter the date of execution. The data from that field will be used four or five times within the document, but I can only bookmark it once.  If I try to cross-reference it, nothing happens.

    thank you,

    Friday, August 28, 2020 3:35 PM

All replies

  • As you appear to have realised, bookmarks must be unique.

    Cross references must be updated in order to display the content

    There is nothing to stop you using two (or more) differently named bookmarks e.g. Date1, Date2 etc and populate them e.g. using the following code

    FillBM "Date1", TextBox1.text

    FillBM "Date2", TextBox1.text

    Public Sub FillBM(strbmName As String, strValue As String)
    'Graham Mayor - http://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
        Set oRng = Nothing
        Exit Sub
    End Sub

    Better still replace the bookmarks with content controls (https://www.gmayor.com/insert_content_control_addin.htm  will do that for you). Two or more content controls can have the same titles. Then populate the content controls with that title e.g.

    Dim oCC As ContentControl
        For Each oCC In ActiveDocument.ContentControls
            Select Case oCC.TITLE
                Case "Date"
                    oCC.Range.Text = TextBox1.Text
            End Select
        Next oCC

    Add cases for each content control title you want to populate.

    Graham Mayor - Word MVP

    Monday, August 31, 2020 3:44 AM