Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 12-23-2019, 02:37 PM
macropod's Avatar
macropod macropod is offline Mail Merge Problem - Run Time Error 5631 Windows 7 64bit Mail Merge Problem - Run Time Error 5631 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

How are you 'selecting' the records to merge?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-23-2019, 02:51 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
Default

Quote:
Originally Posted by macropod View Post
How are you 'selecting' the records to merge?
I select them via Microsoft Word - Mailings - Recipent List
Reply With Quote
  #4  
Old 12-23-2019, 03:07 PM
macropod's Avatar
macropod macropod is offline Mail Merge Problem - Run Time Error 5631 Windows 7 64bit Mail Merge Problem - Run Time Error 5631 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Provided you've unchecked all records, then checked the one(s) you want, there shouldn't be a problem - unless you also have a filter that results in your checked records being filtered out.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-23-2019, 03:31 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
Default

Quote:
Originally Posted by macropod View Post
Provided you've unchecked all records, then checked the one(s) you want, there shouldn't be a problem - unless you also have a filter that results in your checked records being filtered out.
I cleared all selected records and selected a few. That's when the error occurred when I run the macro. There are no filter on my data at all.
Reply With Quote
  #6  
Old 12-23-2019, 03:36 PM
macropod's Avatar
macropod macropod is offline Mail Merge Problem - Run Time Error 5631 Windows 7 64bit Mail Merge Problem - Run Time Error 5631 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the macro under the topic Send Mailmerge Output to Individual Files in the Mailmerge Tips & Tricks 'Sticky' thread at the top of this forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 12-24-2019, 06:39 AM
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
Default

It works, but I can't seem get the code to save merged files into specified folder and not to preview any merged letters. It currently shows all merged letters as individual files each time I run this code and it does not auto close. Any idea?
Reply With Quote
  #8  
Old 01-01-2020, 02:38 AM
macropod's Avatar
macropod macropod is offline Mail Merge Problem - Run Time Error 5631 Windows 7 64bit Mail Merge Problem - Run Time Error 5631 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by simplyez4u View Post
It works, but I can't seem get the code to save merged files into specified folder and not to preview any merged letters.
Read Note 1 following the code in the link. As for previewing - it doesn't, so I don't understand your comment.
Quote:
Originally Posted by simplyez4u View Post
It currently shows all merged letters as individual files each time I run this code and it does not auto close. Any idea?
The code does not show the merged letters - it simply saves them. Only the mailmerge main document remains open.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


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 01:02 PM.


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