Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mailmerge from Access2K (Access/Word 2k (no SR))

    Suddenly, my code for mail merging to Word2k from Access2k has stopped working properly. This is the code, which up until now has worked perfectly.

    Public Function DoALetter()

    On Error GoTo ErrorHandler

    Dim msg As Long
    Dim myApp As Word.Document

    If strActualDoc <> "invoice.doc" Then
    If strActualDoc <> "Astandard.doc" Then
    If IsLoaded("PrintItems") Then
    If IsNull(Forms!PrintItems!Number) Then
    MsgBox "YOU MUST INSERT A NUMBER FOR CONTACT!", vbExclamation, "No Number!"
    Exit Function
    End If
    End If
    End If
    End If

    DoCmd.TransferText acExportMerge, , strQuery, strData, True
    If (IsLoaded("PrintItems")) Then
    DoCmd.Close acForm, "PrintItems"
    End If

    Set myApp = GetObject(strFolderDoc, "Word.Document")
    With myApp
    .Application.Visible = True
    .MailMerge.Destination = wdSendToNewDocument
    .MailMerge.Execute
    .Close (WdSaveOptions.wdDoNotSaveChanges)
    End With


    ErrorHandlerexit:
    Exit Function

    ErrorHandler:
    MsgBox "Error No: " & Err.Number & " - " & Err.Description
    Resume ErrorHandlerexit

    End Function

    It still actually functions but the TransferText action will not transfer 'strData' to its text file because it thinks it is read-only (which it is not). If I delete the text file first, the function will create it again when it is run once. After that it won't run again because it thinks the file is read-only again.

    I should explain that the Word letters have a merge link to this text file as their data source. I find this easier to keep the permanent link and just change the data in the text file.

    Does any one know why it suddenly thinks the file is read-only? Can I run a delete or move file from within the code ( like a DOS batch file)?

    Incidentally, the only change that has occurred is that I just updated from Windows 95 to Windows 2k Pro.

    Any advice would be very much appreciated. Thanks.

    Peter H

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Mailmerge from Access2K (Access/Word 2k (no SR))

    You need to Kill the existing file before you create a new one with the same name. Look for Kill in on-line help.
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mailmerge from Access2K (Access/Word 2k (no SR))

    Charlotte
    Thanks alot. That's sorted it.
    Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •