CurrentData Method

B

Bob

I'm trying to use the following example code from Access 2000's help system:

Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllQueries
If obj.IsLoaded = TRUE then
' Print name of obj.
Debug.Print obj.Name
End If
Next obj

I'm modifying the code to show all queries open or not, so I'm taking out
the isloaded check so it will look somehting like this:

Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllQueries
' Print name of obj.
Debug.Print obj.Name
Next obj

Here is the question - I need the listing to be of another Access database
(MDB file), not the "Current" database. Another thing is ... I need to use
ADO not DAO. I have examples of doing it with DAO, but I'd like to use ADO
or this CurrentData method if possible. Thanks!
 
B

Brendan Reynolds

To use the CurrentData object, you'd have to open a second instance of
Access, which is not very efficient. But here's an example ...

Public Sub TestSub()

Dim objApp As Access.Application
Dim aob As AccessObject

Set objApp = New Access.Application
objApp.OpenCurrentDatabase CurrentProject.Path & "\northwind.mdb"
For Each aob In objApp.CurrentData.AllQueries
Debug.Print aob.Name
Next aob
objApp.CloseCurrentDatabase
objApp.Quit
Set objApp = Nothing

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
A

Andi Mayer

I'm trying to use the following example code from Access 2000's help system:
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllQueries
' Print name of obj.
Debug.Print obj.Name
Next obj

Here is the question - I need the listing to be of another Access database
(MDB file), not the "Current" database. Another thing is ... I need to use
ADO not DAO. I have examples of doing it with DAO, but I'd like to use ADO
or this CurrentData method if possible. Thanks!

you can us the hidden Table MSysObjects and Filter for queries (I
don't have it in my head which flags and Type right now)

If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 

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

Top