Connecting Tech Pros Worldwide Forums | Help | Site Map

Error 5922 when opening a mailmerge document in Word

Newbie
 
Join Date: Nov 2006
Location: Kansas City
Posts: 3
#1: Nov 27 '06
Platform: Access 2003 SP2 and Windows XP.

I've tried a number of different scenarios and none of them seem to work

The "OpenDataSource" statement gives a Run-time error 5922. Please help find my error.

'********************************************

Dim wdApp As Word.Application, wd As Word.Document, strConnection As String
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = False
xPathDoc = "C:\Documents and Settings\BDA Software\LienWaiver.doc"
Set wd = wdApp.Documents.Open(xPathDoc, , True)
Dim wdMM As Word.MailMerge, strSourceFile As String
Set wdMM = wdApp.Documents(xPathDoc).MailMerge
With wdMM
.MainDocumentType = wdFormLetters
.OpenDataSource Name:="C:\Documents and Settings\BDA Software\Database.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblLienWaiver", _
Sqlstatement:="SELECT * from tblLienWaiver"
.Destination = wdSendToPrinter
.SuppressBlankLines = False
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute 'Pause:=False
End With

Set wdMM = Nothing
wd.Close wdDoNotSaveChanges
wdApp.Quit
Set wdApp = Nothing
Exit Sub
' *********************************
Thank you, Willis

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#2: Nov 27 '06

re: Error 5922 when opening a mailmerge document in Word


Willis,

Could you please post the Error Message and perhaps repost the code in the code tags formatted as it would be normally.
That would make life so much easier.
It's really hard to scan through code without any of the visual symbols included in normal code formatting (indentation etc).
Newbie
 
Join Date: Nov 2006
Location: Kansas City
Posts: 3
#3: Dec 10 '06

re: Error 5922 when opening a mailmerge document in Word


Quote:

Originally Posted by NeoPa

Willis,

Could you please post the Error Message and perhaps repost the code in the code tags formatted as it would be normally.
That would make life so much easier.
It's really hard to scan through code without any of the visual symbols included in normal code formatting (indentation etc).

*****************
Below is the code, however the following is selected when I get:
Microsoft Office Word
Quote:
This operation cannot be completed because of dialog or database engine failures. Please try again later
After clicking 'Okay' the following error message is returned:
Quote:
Run-time Error '5922'
the code in quotes is highlighted
*********************

Expand|Select|Wrap|Line Numbers
  1. Dim wdApp As Word.Application
  2. Set wdApp = CreateObject("Word.Application")
  3. wdApp.Visible = False
  4. xPathDoc = "C:\Documents and Settings\BDA Software\LienWaiver.doc"
  5. Dim wd As Word.Document
  6. Set wd = wdApp.Documents.Open(xPathDoc, , True)
  7. Dim wdMM As Word.MailMerge
  8. Set wdMM = wdApp.Documents(xPathDoc).MailMerge
  9. With wdMM
  10.     .MainDocumentType = wdFormLetters
  11.     Quote:
  •  
  •                     .OpenDataSource Name:="C:\Documents and Settings\BDA Software\Database.mdb", _
  •     LinktoSource:=True, _
  •     Connection:="TABLE tblLienWaiver", _
  •     SQLStatement:="SELECT * from tblLienWaiver"
  •  
  •     .Destination = wdSendToPrinter
  •     .SuppressBlankLines = False
  •     With .DataSource
  •         .FirstRecord = wdDefaultFirstRecord
  •         .LastRecord = wdDefaultLastRecord
  •         End With
  •     .Execute 'Pause:=False
  •     End With
  • NeoPa's Avatar
    Administrator
     
    Join Date: Oct 2006
    Location: London - UK
    Posts: 15,730
    #4: Dec 10 '06

    re: Error 5922 when opening a mailmerge document in Word


    I don't know the correct syntax for this command, but I would guess the Connection parameter is wrong. Can you check Help for the correct syntax?
    I would expect something like "TABLE=tblLienWaiver;" but I'm no expert in this.
    Newbie
     
    Join Date: Nov 2006
    Location: Kansas City
    Posts: 3
    #5: Dec 11 '06

    re: Error 5922 when opening a mailmerge document in Word


    Quote:

    Originally Posted by NeoPa

    I don't know the correct syntax for this command, but I would guess the Connection parameter is wrong. Can you check Help for the correct syntax?
    I would expect something like "TABLE=tblLienWaiver;" but I'm no expert in this.

    No, that is not the problem.
    Reply


    Similar Microsoft Access / VBA bytes