Mail merge from Access try to open an already open DB 
Author Message
 Mail merge from Access try to open an already open DB

Hi,

I need some help with my database project in VB 6 using Access & Word
2000.

What I'm trying to do is a mail merge in Word 2000 coded in VB from my
Access application. The problem is that the mail merge always tried to
open a new copy of my Access Database (that is already open) and that
cause me to see a warning message: "The database has been placed in a
state by user 'Admin' on machine 'machinename' that prevents it from
being opened or locked." I see this warning 3 times, then Word finally
 do the mail merge but I now have 3 copies of access running (without
files opened). Then if I close the Word application from my VB code,
Word close and also my running Access application, leaving me only
with my 3 access windows without files opened. Can anybody help me?
here is my code:

'dclare les variables
Dim strFormLetterFile As String
Dim strDataSourceDB As String
Dim strDataSourceQuery As String
Dim strConnect As String
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdMerger As Word.MailMerge

    'nom du formulaire pr-publipost ouvrir
    strFormLetterFile = "C:\mes documents\fr_fax_acc.dot"
    strDataSourceDB = "C:\WINDOWS\Bureau\estimation ACC- word.mdb"
    strDataSourceQuery = "qry_tlcopieur"

    'Create a new instance of word
    Set wrdApp = New Word.Application

    'Open the Word document - the form letter to be sent out
    Set wrdDoc = wrdApp.Documents.Add(strFormLetterFile)

    'establish a MailMerge object using this formletter
    Set wrdMerger = wrdDoc.MailMerge

    With wrdMerger
        .MainDocumentType = wdFormLetters
        .OpenDataSource Name:=strDataSourceDB, _
            LinkToSource:=True, AddToRecentFiles:=False, _
            Connection:="QUERY " & strDataSourceQuery

        .Destination = wdSendToNewDocument
        .DataSource.FirstRecord = 1
        .DataSource.LastRecord = 1
        .Execute
    End With

    'ferme le 1er word contenant le formulaire fusionner
    wrdDoc.Close wdDoNotSaveChanges
    ActiveDocument.SaveAs "ppp.doc"   'TODO: ask filename to user
    ActiveDocument.Close wdDoNotSaveChanges
    wrdApp.Quit

    'return focus to VB and notify when done
    Me.SetFocus
    MsgBox "merge process completed"

    Set wrdApp = Nothing

Thanks
Pierre



Tue, 04 Jan 2005 23:34:13 GMT  
 Mail merge from Access try to open an already open DB
Are you running this code from your open Access program?  Or through a VB
program you have created?.  If you are running it from Access then you
already have your datasource open and do not need to make a connection.

Quote:
> Hi,

> I need some help with my database project in VB 6 using Access & Word
> 2000.

> What I'm trying to do is a mail merge in Word 2000 coded in VB from my
> Access application. The problem is that the mail merge always tried to
> open a new copy of my Access Database (that is already open) and that
> cause me to see a warning message: "The database has been placed in a
> state by user 'Admin' on machine 'machinename' that prevents it from
> being opened or locked." I see this warning 3 times, then Word finally
>  do the mail merge but I now have 3 copies of access running (without
> files opened). Then if I close the Word application from my VB code,
> Word close and also my running Access application, leaving me only
> with my 3 access windows without files opened. Can anybody help me?
> here is my code:

> 'dclare les variables
> Dim strFormLetterFile As String
> Dim strDataSourceDB As String
> Dim strDataSourceQuery As String
> Dim strConnect As String
> Dim wrdApp As Word.Application
> Dim wrdDoc As Word.Document
> Dim wrdMerger As Word.MailMerge

>     'nom du formulaire pr-publipost ouvrir
>     strFormLetterFile = "C:\mes documents\fr_fax_acc.dot"
>     strDataSourceDB = "C:\WINDOWS\Bureau\estimation ACC- word.mdb"
>     strDataSourceQuery = "qry_tlcopieur"

>     'Create a new instance of word
>     Set wrdApp = New Word.Application

>     'Open the Word document - the form letter to be sent out
>     Set wrdDoc = wrdApp.Documents.Add(strFormLetterFile)

>     'establish a MailMerge object using this formletter
>     Set wrdMerger = wrdDoc.MailMerge

>     With wrdMerger
>         .MainDocumentType = wdFormLetters
>         .OpenDataSource Name:=strDataSourceDB, _
>             LinkToSource:=True, AddToRecentFiles:=False, _
>             Connection:="QUERY " & strDataSourceQuery

>         .Destination = wdSendToNewDocument
>         .DataSource.FirstRecord = 1
>         .DataSource.LastRecord = 1
>         .Execute
>     End With

>     'ferme le 1er word contenant le formulaire fusionner
>     wrdDoc.Close wdDoNotSaveChanges
>     ActiveDocument.SaveAs "ppp.doc"   'TODO: ask filename to user
>     ActiveDocument.Close wdDoNotSaveChanges
>     wrdApp.Quit

>     'return focus to VB and notify when done
>     Me.SetFocus
>     MsgBox "merge process completed"

>     Set wrdApp = Nothing

> Thanks
> Pierre



Sun, 16 Jan 2005 10:31:13 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mail merge using DDE opens Access twice

2. VB tries to Open MS Access DB [ERROR]

3. App tries to open DB as MS Access 1.1 fmt instead of 2.0

4. VB tries to Open MS Access DB [ERROR]

5. MSG: Database already open when trying to compact???

6. Can set a ref to 1 open db but not another open db - error 3045

7. Opening Merge Document tries to remerge the document

8. How can i block opening a form that is already open

9. How to open a file for read that is already open by another application

10. ShellExecute only opens file.htm if browser already open

11. Open an already opened file

12. Mail Merge - Word was unable to open the datasource

 

 
Powered by phpBB® Forum Software