Set Access.Application object to an external, already open Access file.

  • Thread starter Thread starter Jeremy Gollehon
  • Start date Start date
J

Jeremy Gollehon

From Access VBA I can control a specific word doc like so:
---------------------------------------------------------------------------­-
Sub GetWordDoc()
Dim appWd As Word.Application
Dim docName As String

docName = "D:\MyFolder\MyDoc.doc"

On Error Resume Next
Set appWd = GetObject(, "Word.Application")
If appWd Is Nothing Then
Set appWd = New Word.Application
End If

If Not appWd.Documents(docName) Is Nothing Then
appWd.Documents.DoWhatever
End If
On Error GoTo 0

Set appWd = Nothing

End Sub
---------------------------------------------------------------------------­-

The .Documents collection allows for this functionality. If more than one
instance of Word is open the Documents collection gets me to the specific
file I'd like to work with.
How would I approach the same thing when referencing another Access file?
appAccess.???
Ultimately I'm looking to close one Access file from another.

Thanks,
-Jeremy
 
You probably can only close what you opened. Maybe something like this or
use a macro or code in the other DB to kill itself.

Dim appAccess, strConPathToDB
strConPathToDB = "D:\data\Access\db1.mdb"
Set appAccess = CreateObject("Access.Application.11")
appAccess.OpenCurrentDatabase strConPathToDB
appAccess.DoCmd.RunMacro "TestMacro"
appAccess.CloseCurrentDatabase
appAccess.Quit
Set appAccess = Nothing

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| From Access VBA I can control a specific word doc like so:
| ---------------------------------------------------------------------------­-
| Sub GetWordDoc()
| Dim appWd As Word.Application
| Dim docName As String
|
| docName = "D:\MyFolder\MyDoc.doc"
|
| On Error Resume Next
| Set appWd = GetObject(, "Word.Application")
| If appWd Is Nothing Then
| Set appWd = New Word.Application
| End If
|
| If Not appWd.Documents(docName) Is Nothing Then
| appWd.Documents.DoWhatever
| End If
| On Error GoTo 0
|
| Set appWd = Nothing
|
| End Sub
| ---------------------------------------------------------------------------­-
|
| The .Documents collection allows for this functionality. If more than one
| instance of Word is open the Documents collection gets me to the specific
| file I'd like to work with.
| How would I approach the same thing when referencing another Access file?
| appAccess.???
| Ultimately I'm looking to close one Access file from another.
|
| Thanks,
| -Jeremy
|
|
 
John,
Exactly what I was looking for. Thanks.
Now I can truely compact and repair from code. See my forthcoming post.

-Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top