Full Version: code to close this database and open another database
UtterAccess Forums > Microsoft® Access > Access Forms
Powelldog
hi again
want to use cal2007 to automatically back up my database
from a button I want to have this happen: Open C:\TechBase\cal2007.accdb
then Close the Database that I am currently using
There is what I have so far it will open cal2007, I am not sure what code will close the current database.
CODE
Private Sub BackupDatabase_Click()
On Error GoTo Err_cmdSecondryDB_Click
    
    Dim strRun As String
    Dim strAcessLocation As String
    Dim stAppName As String
    Dim strQuote As String
'Define access
   strAcessLocation = "C:\Program Files\Microsoft Office\OFFICE12\MSACCESS.EXE"
'Define App
    stAppName = "C:\TechBase\cal2007.accdb"
' "
strQuote = Chr(34)
strRun = strQuote & strAcessLocation & strQuote & " " & strQuote & stAppName & strQuote
   Call Shell(strRun, 1)
Exit_cmdSecondryDB_Click:
    Exit Sub
Err_cmdSecondryDB_Click:
    MsgBox Err.Description
    Resume Exit_cmdSecondryDB_Click
End Sub
'------------------------------------------------------------
' Relink_Click
'
'------------------------------------------------------------
Private Sub Relink_Click()
On Error GoTo Relink_Click_Err
    DoCmd.Close , ""
    DoCmd.OpenForm "Admin_Utilities", acNormal, "", "", , acNormal
    
Relink_Click_Exit:
    Exit Sub
Relink_Click_Err:
    MsgBox error$
    Resume Relink_Click_Exit
End Sub

thanks David
dannyseager
how about adding
!--c1-->
CODE
docmd.exit

after
CODE
Call Shell(strRun, 1)
dannyseager
Sorry... that should have been
!--c1-->
CODE
Docmd.quit
Powelldog
Great!
That worked perfect
I just was puting the Docmd.quit in the wrong place, it would close the database before the other app would open
Thanks again
David
dannyseager
you're welcome
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.