Aug 29 2011, 09:49 AM
I am attempting to use GetObject from vbScript to build a reference to a specific Access database. When I don't specific that PathName argument, I can't gurantee that the database I want to be returned will be as users typically run multipe access applications. When I do specify the pathname there is an interesting issue. If the file I specify in the pathname is not open, the script will automatically open the file at that location. Does anyone know of a way of preventing this, or an alternate way of referring to a specific access file within vbscript? Any help would be greatly appreciated.
Aug 29 2011, 09:54 AM
Are you actually using vbScript (.vbs file), or is this a VBA procedure hosted by an Access instance? (I asked because of the Forum the Topic is in -- 'Access Automation')
Aug 29 2011, 10:00 AM
>> If the file I specify in the pathname is not open, the script will automatically open the file at that location. <<
That is the definition of what GetObject() does:
From the help:
"When this code is executed, the application associated with the specified pathname is started and the object in the specified file is activated.If pathname is a zero-length string (""), GetObject returns a new object instance of the specified type. If the pathname argument is omitted, GetObject returns a currently active object of the specified type. If no object of the specified type exists, an error occurs."
>> ... to build a reference to a specific Access database. <<
What are you trying to get to in the Access file.
Aug 29 2011, 10:33 AM
The script runs from within the terminal emulator. I was thinking this was the correct place as it deals with automation of Access. Is there another area that would fit better?
Aug 29 2011, 11:07 AM
I am running a procedure from within the access file using Application.Run . This means, I just need to get a reference to the application object. What I have been doing so far, is not specifying a pathname, and then testing the CurrentDb property of the application object to see if it's my database. This gets me close, but if it is not my database I just don't execute anything. Thank you for the help.
Aug 29 2011, 03:02 PM
You can use Automation to create your own instance of an Access object. It won't matter is the user has it opened or not.
Public Sub RunRemoteCode()
Dim app As Access.Application
Set app = New Access.Application
Set app = Nothing
With this ... If your user also has the database you remote into, and your procedure modifies data that the user may be viewing, you may want to have a "Refresh" button or something like so the users can get the ensure they have the latest data visible to them.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here