Results 1 to 11 of 11
  1. #1
    ahmd01 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    4

    Trying to save open MS Access documents with a script

    Hi everyone:

    I'm trying to automate saving of all open documents in our computer room before performing a nightly installation of updates and a later reboot. For that I need first to save all open MS Office documents. The way I do it with most Office documents from an outside script is as follows:



    Code:
    var objAccess = GetObject("", "Access.Application");
    //Then I'd enumerate all open documents in the .Documents property
    //and call Documents.Item(n).SaveAs() method on each of them
    But for some reason I can't do the same with MS Access. Can someone suggest how do I close all open documents in it with an option of saving them As in a file from a script?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what language is the script in? vbscript?

  3. #3
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    An alternative approach might be to have the applications automatically shut down after a specified period of user inactivity. This would be an internal approach as opposed to attempting to shut the app down externally via a script. Here's a free tool to help with that: http://peterssoftware.com/isd.htm

  4. #4
    ahmd01 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    4
    Thank you, both. The language that it's written on does not matter to me -- I started with JScript but you can do it in VBScript. As for any alternative program, then no, I can't "implant" anything into user documents...

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by ahmd01 View Post
    Thank you, both. The language that it's written on does not matter to me -- I started with JScript but you can do it in VBScript. As for any alternative program, then no, I can't "implant" anything into user documents...
    i'm surprised that you can execute a SAVEAS() command on any open documents. office docs of any kind create temp files when they are opened. It might be due to the fact that access is 3-dimensional. Locked by default, unless it's being opened ''SHARED''.

    I wouldn't think you could close the docs with a script. Must be some admin function you can do with it. I'm not sure what that would be though. That's all I personally have for this thread.

  6. #6
    pdebaets is offline Competent Performer
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Los Angeles
    Posts
    235
    Edited message... still thinking about this one...

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Just like I shared with you on the MSDN forums, you can't do this with Access because there isn't a way to capture and enter an open session of Access. The only way would be if you could log on to the currently open computer into the user's session and then go to the open database and then save the objects. But actually connecting code to do that and also to attach to the open session of Access I believe is not possible.

  8. #8
    ahmd01 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    4
    Thanks. I guess it's not possible with Access. As for other Office products saving a document is as easy as I outlined in my original post.

  9. #9
    ahmd01 is offline Novice
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    4
    Well, guys, I might have found the method to save changes & quit Access (note that this code runs from outside. I also converted it to VB since that is the language that most Access developers use):
    Code:
    Dim objAccess 
    Set objAccess = GetObject(,"Access.Application") 
    objAccess.Quit(1) ' acQuitSaveAll 

  10. #10
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    umm - I'd be surprised if that actually works - unless you are running Citrix or Terminal Services and the sessions are actually running on the server (and you can iterate through each user's session - logging on as them). Access opens and runs on the machine which opened it. So, if a user is running Access from their machine or from a file on the file server, then you would have to log in as that user on that machine (either in person or by RDP) in order to run the code and to have any chance of it actually working properly.

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Oh, and one more consideration - what if they have more than one Access database open?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access to merge documents
    By SJames in forum Access
    Replies: 2
    Last Post: 04-25-2011, 09:27 AM
  2. Replies: 9
    Last Post: 01-20-2011, 02:22 PM
  3. Categorizing Word documents with Access
    By radagast in forum Access
    Replies: 0
    Last Post: 06-14-2009, 12:06 AM
  4. Open / Save as Excel File and specifiy format
    By jaykappy in forum Access
    Replies: 8
    Last Post: 03-24-2009, 03:26 PM
  5. Open Accesss DB by batch script
    By micada in forum Access
    Replies: 0
    Last Post: 06-10-2008, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums