By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

Error 5922 when opening a mailmerge document in Word

P: 3
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
Nov 27 '06 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,660
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).
Nov 27 '06 #2

P: 3
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
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:
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.  
  12.         
  13.                     .OpenDataSource Name:="C:\Documents and Settings\BDA Software\Database.mdb", _
  14.     LinktoSource:=True, _
  15.     Connection:="TABLE tblLienWaiver", _
  16.     SQLStatement:="SELECT * from tblLienWaiver"
  17.  
  18.     .Destination = wdSendToPrinter
  19.     .SuppressBlankLines = False
  20.     With .DataSource
  21.         .FirstRecord = wdDefaultFirstRecord
  22.         .LastRecord = wdDefaultLastRecord
  23.         End With
  24.     .Execute 'Pause:=False
  25.     End With
Dec 10 '06 #3

NeoPa
Expert Mod 15k+
P: 31,660
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.
Dec 10 '06 #4

P: 3
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.
Dec 11 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.