Full Version: Prevent Getobject From Opening File
UtterAccess Discussion Forums > Microsoft® Access > Access Automation
accessdev1
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.
datAdrenaline
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')
datAdrenaline
>> 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.

accessdev1
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?
accessdev1
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.
datAdrenaline
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.

CODE
Public Sub RunRemoteCode()
    
    Dim app As Access.Application
    
    Set app = New Access.Application
    
    With app
        
        .OpenCurrentDatabase "thePathAndNameOfYourFile"
        
        .Run "yourProcedureName"
        
        .CloseCurrentDatabase
        
        .DoCmd.Quit
        
    End With
    
    Set app = Nothing

End Sub


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.