Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-23-2019, 01:21 PM
simplyez4u simplyez4u is offline Mail Merge Problem - Run Time Error 5631 Windows 10 Mail Merge Problem - Run Time Error 5631 Office 2019
Novice
Mail Merge Problem - Run Time Error 5631
 
Join Date: Dec 2019
Posts: 5
simplyez4u is on a distinguished road
Question Mail Merge Problem - Run Time Error 5631

Hi,


I create an Access database as data source. The mail merge grabs the data from the database and feeds into a letter. The macro, which I found online, only works when all entries are selected. It runs fine and splits out each letter with a pre-defined file name. However, when I only select few entries (like entry 2, 5, 9, 11), it gives me a run time error 5631.
VBA Error Screenshot


Below is my VBA code
Code:
Sub SaveAsFileName()
Dim FileName  As String
With ActiveDocument.MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True

    For SectionCount = 1 To .DataSource.RecordCount
        With .DataSource
            ActiveDocument.MailMerge.DataSource.ActiveRecord = SectionCount
            ActiveDocument.MailMerge.DataSource.FirstRecord = SectionCount
            ActiveDocument.MailMerge.DataSource.LastRecord = SectionCount

            'replace Filename with the column heading that you want to use - can't have certain symbols in the name
            FileName = .DataFields("Letter").Value & "_" & .DataFields("Name").Value
        End With

        'Get path and file name
        FullPathAndName = ActiveDocument.Path & Application.PathSeparator & FileName & ".docx"

        'Merge the document
        .Execute Pause:=False

        'Save resulting document.
        ActiveDocument.SaveAs (FullPathAndName)
        ActiveDocument.Close False
    Next
End With
End Sub

Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge Problem - Run Time Error 5631 Unexpected Big Problem With Mail Merge via Excel VBA - DataLink Problem JennEx Mail Merge 6 05-26-2019 06:08 AM
vba error when trying to do a mail merge texas1014 Mail Merge 1 03-08-2017 03:23 PM
Help Please: New VBA user trying to use a macro to split Mail Merge documents. Two Run-Time Error zipit189 Word VBA 7 03-18-2015 01:13 PM
time field issue in mail merge Aude Mail Merge 16 05-18-2014 06:22 AM
Mail Merge Problem - Run Time Error 5631 Error 5631 in Mail Merge DoctorNadir Mail Merge 7 12-16-2011 04:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft