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,
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,