Mail merge problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    Mail merge problem

    I am trying to do a mail merge from Access 2000/2002 through VBA to a
    Word document. It all works fine on all Windows 2000 machines
    (regardless of if it is Office 2000 or 2002) but it doesn't work on
    any Windows XP machines. I get a 4605 error and there is no
    documentation I can find on this anywhere on the internet. I have
    checked file permissions on all files. I get errors on the 2 lines
    marked XX. The Word document is not protected. It works fine on
    Windows 2000 but not Windows XP.
    The error messages I get are:
    "this method or property is not available because the document is a
    protected document. (4605)"
    "The OpenDataSource method or property is not available because the
    object refers to a protected area of the document. (4605)". I only got
    this error when i had the OpenDataSource line in the code, which i
    have now commented out.

    The code is:

    Set pappWord = CreateObject("W ord.Application ")
    pappWord.Docume nts.Add Application.Cur rentProject.Pat h & "\Job
    document.doc"
    strDocName = pappWord.Active Document

    'Check for existence of previously saved letter in documents
    folder,
    'and append an incremented number to save name if found
    strDocType = pappWord.Active Document.BuiltI nDocumentProper ties(2)
    strSaveName = strDocType & ".doc"
    strDBPath = Application.Cur rentProject.Pat h & "\"
    strTextFile = strDBPath & "job.txt"
    strDocName = pappWord.Active Document

    'Set the merge data source to the text file just created,
    'and do the merge to a new document
    With pappWord
    '.ActiveDocumen t.MailMerge.Ope nDataSource _
    ' Name:=strTextFi le, _
    ' LinkToSource:=F alse, Format:=wdOpenF ormatText,
    ReadOnly:=True
    .ActiveDocument .MailMerge.Dest ination = wdSendToNewDocu ment
    .ActiveDocument .MailMerge.View MailMergeFieldC odes = False
    XX .ActiveDocument .MailMerge.Exec ute

    .Application.Br owser.Target = wdBrowsePage

    'For i = 1 To
    ..ActiveDocumen t.BuiltInDocume ntProperties("N umber of Pages")

    'Select and copy the text to the clipboard
    XX .ActiveDocument .Bookmarks("\pa ge").Range.Co py

    ' Open new document to paste the content of the clipboard
    into.
    .Documents.Add
    .Selection.Past e

    ' Removes the break that is copied at the end of the page, if
    any.
    .Selection.Type Backspace
    .ChangeFileOpen Directory "C:\"
    If zeroorone = 0 Then
    .ActiveDocument .SaveAs
    FileName:=Forms ("frmJobNew3"). Controls("txtJo bDirectory") & "/" & "Job
    Document " & Forms("frmJobNe w3").Controls(" txtJobID") & " version " &
    Forms("frmJobNe w3").Controls(" txtversionnumbe r") & ".doc"
    Else
    'MsgBox Forms("frmJobDe tails").Control s("txtJobDirect ory")
    & "/" & "Job Document " & Forms("frmJobDe tails").Control s("txtJobID")
    & " version " & Forms("frmJobDe tails").Control s("txtversionnu mber") &
    ".doc"
    .ActiveDocument .SaveAs
    FileName:=Forms ("frmJobDetails ").Controls("tx tJobDirectory") & "/" &
    "Job Document " & Forms("frmJobDe tails").Control s("txtJobID") & "
    version " & Forms("frmJobDe tails").Control s("txtversionnu mber") &
    ".doc"
    End If

    '.Document.fitt opage

    .ActiveDocument .Close savechanges:=wd DoNotSaveChange s

    ' Move the selection to the next page in the document
    '.Application.B rowser.Next
    'Next i
    .ActiveDocument .Close savechanges:=wd DoNotSaveChange s
    .Documents.Clos e savechanges:=wd DoNotSaveChange s

    '.ActiveDocumen t.Close SaveChanges:=wd DoNotSaveChange s
    .Quit
    End With

    Set pappWord = Nothing


    Can someone help?

    Thanx
Working...