开发者

What is the correct "Document Name" of an Access ADP/MDB to use in the GetObject("Document Name") call?

According to http://support.microsoft.com/kb/288902/en-us

You can attach to a specific instance if you know the name of an open docu开发者_JAVA百科ment in that instance. For example, if an instance of Excel is running with an open workbook named Book2, the following code attaches successfully to that instance even if it is not the earliest instance that was launched:

Set xlApp = GetObject("Book2").Application

Th example works for Excel, mainly because the "Document Name" is nearly the same as the filename. I need to get this to work for Access.

I have users running multiple instances of different Access Applications (.ADP) and I need to get one with a specific name. I do NOT know the complete filepath, otherwise I could do a simple

Set app = GetObject("c:\my\app\myapp.adp", "Access.Application")

Currently, I go with calling

Set app = GetObject(, "Access.Application")

and check the returned Application.Name. If it's good, I use it to call some functions on it, if not it fails. I have heard about the Running Objects Table, but since I have to get the object inside a VBScript, it's a bit too much API-calls.

Bottom Line: What is the correct "Document Name" of an Access ADP to use in the GetObject("Document Name") call and what type of object does it return?


Coming back to this question because @phoog posted an answer, it occurs to me that since Access can have only one database open at a time, you'd need to look at each instance of Access and check its CurrentDB.Name. Now, with an ADP, I don't know what you'd check instead, but perhaps it's CurrentProject.Path.

I don't believe any of that actually addresses the original question, which seems to want to find the instance with just the filename, but I don't think that even if that worked it would be a good idea. You could easily have independent Access apps that return the same application name and filename but are stored in different locations in the file system.


You probably want to read this: http://support.microsoft.com/kb/147816

Unfortunately, it looks like "Document Name" has to be the mdb file, so if you don't know the file path, you're not going to be able to use "Document Name".

In addition to the fact that Excel can have multiple documents per instance, Excel also prevents you from opening two documents with the same name, even if they are in different folders and you are opening them in different instances of Excel.

On the other hand (to address David-W-Fenton's comment), Access does allow you to open multiple instances of the same database (not to mention different databases with the same name), as long as you don't open any instance in exclusive mode.

This is further evidence that the way Excel registers its documents in the ROT is very different from the way Access does so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜