Close Another Database

Joshann

Registered User.
Local time
Today, 07:28
Joined
Mar 22, 2002
Messages
142
I am using code in Access to run a merge in Word. I'll call the database containing the function (MergeWord) that runs the merge Database1. The table used in the merge is in a different database. I'll call the database that contains the table Database2. When the merge is run, another instance of Access is automatically opened with Database2 open. How do I close the second instance of Access (Database2)?

Here's my code so far:
Code:
Function MergeWord()
    Dim ObjWord As Word.Document
    Set ObjWord = GetObject("H:\SHARED\FORMS\Test.doc", "Word.document")
    ObjWord.Application.Visible = True
    ObjWord.MailMerge.OpenDataSource NAME:="H:\Access\Database2.mdb", Linktosource:=True, Connection:="TABLE NewFileExport"
    ObjWord.MailMerge.Destination = wdSendToNewDocument
    ObjWord.MailMerge.Execute
    ObjWord.Application.NormalTemplate.Saved = True
    ObjWord.Activate
    ObjWord.Close False
    
    Set ObjWord = Nothing
    
    Exit Function
End Function
 
Try
ObjWord.ScreenUpdating False
'
' Your Code
'
ObjWord.ScreenUpdating True
 
Boot said:
Try
ObjWord.ScreenUpdating False
'
' Your Code
'
ObjWord.ScreenUpdating True

Unfortunately, that didn't work. I get the following error message: "Object doesn't support this property."
 
It works for me in Excel. I thought it would with word too. Try Putiing a reference to Microssoft word Object Library. then
ObjWord.Application.ScreenUpdating=False
'
' Your Code
'
ObjWord.Application.ScreenUpdating=True
 
Boot said:
It works for me in Excel. I thought it would with word too. Try Putiing a reference to Microssoft word Object Library. then
ObjWord.Application.ScreenUpdating=False
'
' Your Code
'
ObjWord.Application.ScreenUpdating=True

I already have a reference to the Microsoft Word Object Library.
 
Try this:

objAccess.Quit
Set objAccess = Nothing
 
I finally got it to work. First I had to open the other instance of Access myself rather than letting Word open it:

Code:
Dim ObjAccess As Object
Set ObjAccess = GetObject("H:\Access\Database2.mdb")

Then I was able to use:

Code:
ObjAccess.Quit

Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom