[AccessD] error after converting (mailmerge)

MartyConnelly martyconnelly at shaw.ca
Wed Jan 21 17:00:16 CST 2004


I can get this to work with Access97 to Word2003 (my default) by 
dropping some extraneous code,ie. not using connection string.
The mdb I am opening is seperate from the one I am running Access in.

It does however open 2 copies of word  1 default (document3.doc) and 1 
(form letters1.doc)
It also prints too. does not close either word document.

Sub test()
Dim bltest As Boolean
bltest = True
CreateMergeDoc bltest, True
End Sub
Sub CreateMergeDoc(UseDDE As Boolean, PrintDoc As Boolean)
  
   Dim WordDoc As Word.Document
   Dim strLetter As String
   Dim strConnect As String
   Dim WordApp As Word.Application
  
   Set WordApp = CreateObject("Word.Application")
  
   Set WordDoc = WordApp.Documents.Add
   With WordDoc.MailMerge
     
      .OpenDataSource _
          Name:="C:\Documents and Settings\marty\My 
Documents\WordMergetestold97.mdb", _
          ReadOnly:=True, LinkToSource:=True, _
          SQLStatement:="SELECT * FROM [Table1] WHERE Table1.MyField = " 
& 123 & ";"
    
     ' With Fields
      '...............
      'End With

      'With WordApp.Selection
      '...............
      'End With


      With WordDoc.MailMerge
      .DataSource.FirstRecord = 1
      Debug.Print .DataSource.TableName
      .Destination = wdSendToNewDocument
     
      .Execute
     
      If PrintDoc Then
         .Application.Options.PrintBackground = False
         .Application.ActiveDocument.PrintOut
      End If
   End With
  
   WordApp.Visible = True
   End With
End Sub

pedro at plex.nl wrote:

>Hello Group,
>
>i converted a A97 secured database to A2K. 
>After making the changes in Wrkgadmin.exe and the ODBC Data Sources, i changed the names in the module. After running the mailmerge i get an error: Run-time error '5922' Word was unable to open the data source. The debug selects the .OpenDataSource from the code below.
>
>I figure out why this error occurs.
>
>TIA
>
>Pedro Janssen
>
>
>
>
>Sub CreateMergeDoc(UseDDE As Boolean, PrintDoc As Boolean)
>   
>   Dim WordDoc As Word.Document
>   Dim strLetter As String
>   Dim strConnect As String
>   Dim WordApp As Word.Application
>   
>   Set WordApp = CreateObject("Word.Application")
>   
>   Set WordDoc = WordApp.Documents.Add
>   With WordDoc.MailMerge
>      If UseDDE Then
>         strConnect = "QUERY Uitvoer"
>      Else
>         strConnect = "DSN=MS Access 2000 " _
>         & "Database;DBQ=E:\Cytologie\positieven\" _
>         & "BeveiligdPOSITIEVEN(A2K).mdb;" _
>         & "FIL=MS Access;"
>      End If
>      .OpenDataSource _
>          Name:="E:\Cytologie\positieven\BeveiligdPOSITIEVEN(A2K).mdb", _
>          ReadOnly:=True, LinkToSource:=True, _
>          Connection:=strConnect, _
>          SQLStatement:="SELECT * FROM [Uitvoer], [Aanvrager] WHERE Uitvoer.AanvragerID = Aanvrager.AanvragerID AND Uitvoer.ControleID = " & Forms![Brief]![veld] & ";"
>      
>      With Fields
>      ...............
>      End With
>
>      With WordApp.Selection
>      ...............
>      End With 
>
>
>      With WordDoc.MailMerge
>      .DataSource.FirstRecord = 1
>      
>      .Destination = wdSendToNewDocument
>      
>      .Execute
>      
>      If PrintDoc Then
>         .Application.Options.PrintBackground = False
>         .Application.ActiveDocument.PrintOut
>      End If
>   End With
>   
>   WordApp.Visible = True
>   End With
>End Sub
>
>_______________________________________________
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada





More information about the AccessD mailing list