Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate Duplicate fields 1

Status
Not open for further replies.

keenanbr

Programmer
Oct 3, 2001
469
IE
I'm trying to write a macro to populate duplicate formfields. I have the naming convertion; Field to be duplicated - Name, Duplicate Fields DufName01, DufName02 etc.

The macro i have so far is:

Public Sub PopulateDuplicateFields()
Dim Bmk() As String
Dim i As Integer, j As Integer
Dim OrigBMName As String
Dim BM As String
Dim sResult As String

On Error GoTo ErrorHandler

MsgBox ("pop dup form fields")

If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
ActiveDocument.Protect Type:=wdNoProtection, NoReset:=True
End If

i = ActiveDocument.FormFields.Count

ReDim Bmk(i)

For j = 1 To i
Bmk(j) = ActiveDocument.FormFields(j).Name
Next j

For j = 1 To i
If Left$(Bmk(j), 3) = "Duf" Then
BM = Bmk(j)
MsgBox (BM)
OrigBMName = Mid$(BM, 4, Len(BM) - 5)
sResult = ActiveDocument.FormFields(OrigBMName).Result
ActiveDocument.FormFields(BM).Result = sResult
'Selection.Text = sResult
'ActiveDocument.FormFields(BM).Enabled = True
End If
Next j

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If

Exit Sub
ErrorHandler:
MsgBox ("Error in PopulateDuplicateFields " & j & " " & Err.Description)
End Sub

I call this on exit from the last original formfield and it populates the duplicate fields.


What I would like to do is call a macro after each formfield input and populate its duplicates and then position the cursor on the next original field.


Any ideas.

Regards,

 
Hi keenanbr,

You're making this much harder than you need to.

All you need is to have one formfield set a bookmark (eg 'Text1'), set that formfield's properties to 'calculate on exit', and use REF fields to point back to the 'Text1' bookmark.

Then, anytime you update your 'Text1' formfield, all the REF fields will update automatically. No vba required.

Cheers

[MS MVP - Word]
 
But I have 300 templates to do and I want to use a general macro for them all.
 
Sorry for being so quick to dismiss your suggestion. I think I can use REF fields.

Regards,

Brian

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top