Results 1 to 6 of 6
  1. #1
    peterFisp is offline Novice
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Location
    Australia
    Posts
    18

    Closing a database but not the Access Application

    Having gotten interested in closing Access from a form, I got the following code working:



    Code:
        DoCmd.Quit acQuitSaveAll
    ''     Access.Quit            '  this also quits the application after saving any mods  I cannot see any difference
    ''       DoCmd.Quit                 ''' 
    all of these variations will quit the application as well 
    In each case, any edits are saved automatically, and then the Application closes alright.

    Is there code that I can run to only close the open database, but not Access?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Manually closing a database causes Access to set focus on File>New menu item. Access is not like Excel where single application frame can open multiple files. An Access database is basically an application unto itself. Each must have its own Access shell (rather more like Word where each doc has its own shell, but a doc can be closed and leave a blank display, doesn't automatically shift to File>New). I've never seen code that will close a db and set the Access frame on File>New.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    peterFisp is offline Novice
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Location
    Australia
    Posts
    18
    OK, I just have to accept that. However, when I open Access from the task bar it does not display any database, only the Getting Started stuff. So I presumed it should be possible to replicate that outcome just as it's done first up.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The VBA command would be "DoCmd.CloseDatabase" (see Help)..... but I don't know why you would ever want to use this unless maybe you were using VB/C/C# automation.


    BTW, using the acQuitSaveAll parameter doesn't do what you think it does. When closing/quitting Access, the DATA is automatically saved.
    The parameter acQuitSaveAll saves changes to the DESIGN of the data base. If you used VBA to open a form in design view and added a control, you have the choice (acQuitPrompt) to save the changes to the form of discarding the changes.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Okay, that did go to File>New. I also don't see any benefit. Not finding a DoCmd method to open a new or recent db into this same frame, unless it's buried somewhere in DoMenuItem.

    DoCmd.RunCommand acCmdOpenDatabase appears to be a deadend.

    Everything I see involves closing one shell and opening another.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    peterFisp is offline Novice
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Location
    Australia
    Posts
    18
    Thanks, Steve.
    Beautiful, that does it; I just wanted to see if it can be done. And actually I did not think the former and had observed the latter. I have used Access for very long time and never found it to have lost data.

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

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2018, 02:23 PM
  2. Closing access database without saving
    By onaggar in forum Access
    Replies: 7
    Last Post: 12-19-2013, 06:23 PM
  3. Closing the application with some timer
    By reachvali in forum Programming
    Replies: 1
    Last Post: 05-18-2010, 11:28 PM
  4. Ms Access database application
    By delhiris in forum Access
    Replies: 3
    Last Post: 02-21-2010, 06:15 PM
  5. Replies: 9
    Last Post: 12-28-2009, 04:01 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