Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Run-time error '5922' - Mail Merge

  1. #1
    Board Regular
    Join Date
    Jun 2013
    Location
    Ashford, Surrey
    Posts
    233
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Run-time error '5922' - Mail Merge

    Morning all,

    I am attempting to automate a mail merge in word, with the source being an excel spreadsheet. I've included my code below, but it always give me the error "Run-time error '5922': Word was unable to open the data source."

    I think it may have something to do with the format being set incorrectly, but I'm really unsure. Also, I haven't yet managed to have it generate the dialogue from which you can choose the source within the excel document.

    Any help you guys could give me would be much appreciated.

    Code:
    Sub MailMerge()
    
        Dim SourceDoc As String
        Dim SelectedItems(1) As String
    
    
        With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = False
            If .Show <> 0 Then
                SelectedItems(1) = SourceDoc
            Else
                Exit Sub
            End If
        End With
        
        ActiveDocument.MailMerge.OpenDataSource Name:=SourceDoc, _
            ConfirmConversions:=True, ReadOnly:=False, LinkToSource:=True, _
            AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
            WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
            Format:=wdOpenFormatAuto, Connection:= _
            "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=H:\Jonathon Hunter Hill\Mail Merge\AirMaster V 0.9.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:" _
            , SQLStatement:="SELECT * FROM `MailMerge$`", SQLStatement1:="", SubType _
            :=wdMergeSubTypeAccess
            
    End Sub

  2. #2
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,715
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run-time error '5922' - Mail Merge

    In your SQL string you have references to both SourceDoc and H:\Jonathon Hunter Hill\Mail Merge\AirMaster V 0.9.xlsm. You should have one or the other; otherwise there's a risk of ambiguity and conflict.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    Moderator Macropod's Avatar
    Join Date
    Aug 2007
    Location
    Canberra, Australia
    Posts
    2,715
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run-time error '5922' - Mail Merge

    Cross-posted at: Run-time error '5922' - Mail Merge
    For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
    Cheers
    Paul Edstein
    [MS MVP - Word]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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