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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word mailmerge combined with form 2

Status
Not open for further replies.

jel

Programmer
Feb 17, 2002
349
NL
I want to do a mailmerge (document type = form letter) on a document that is a form: it contains form fields and is 'protected for forms'.
This operation is to be carried out by VB code, addressing Word from outside.
This way, I want the user of my application to be able to create a document and have my application fill in some fields (by means of the mail merge), and another user fill in some other fields (by filling in a protected form).

I have no problem coding the merge itself, and provided the password is known it is possible to remove and put back the forms-protection.
So, it all works well exept for one thing: Word removes the text-formfields. Checkboxes and combos survive the operation, but all text-input-fields are gone.

Anybody any idea why, and how to prevent it?
 
How about:

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


Never take a sleeping pill and laxative at the same time
 
No, I had no problems removing the protection.
The problem I have is that form-fields type text are converted to text. Combo's and checkboxes remain as formfields, text-fields do not.

This is the VBA-code I use to test it:
Code:
Public Sub MergeThatThing()
    Dim lngP As Long

    lngP = ActiveDocument.ProtectionType
    
    If lngP = 2 Then
        ActiveDocument.Unprotect "blah"
        'ActiveDocument.ProtectionType = wdNoProtection
    End If

    With ActiveDocument.MailMerge
        .MainDocumentType = wdFormLetters
        .OpenDataSource "c:\temp\blah.txt"
        .Execute
        If lngP = 2 Then
            ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
        End If
    End With

End Sub
 
See Microsoft Knowledge Base Article - 211308
WD2000: Text Form Fields Are Not Retained During Mail Merge

 
Exactly what I was looking for - feel stupid to have overlooked it. Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top