Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2004
    Posts
    10

    Unanswered: Close a database with code.

    I have the following code that I use to open a database and print a report. However, I want the code to close the database once the report is printed. The current code for that step does not work. Any advice?

    Private Sub Command16_Click()

    Dim appAccess As Access.Application
    fOpenRemoteReport2 "rptClassDetailsForDateRange", "K:\APPLICTN\Access\Training Database.mdb"
    End Sub

    Function fOpenRemoteReport2(strReport As String, strMDB As String) As Boolean

    If IsMissing(strMDB) _
    Or Len(strMDB) = 0 Then
    ' Open form in current db
    DoCmd.OpenReport strReport

    Else
    ' Create new instance of Microsoft Access.
    Set appAccess = _
    CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strMDB
    ' Open required report from within the OTHER database.
    appAccess.DoCmd.OpenReport strReport
    ' Close the database.
    DoCmd.Close acDefault, strMDB, acSaveNo
    Set appAccess = Nothing
    End If

  2. #2
    Join Date
    Sep 2003
    Posts
    228
    DoCmd.Quit

    not close

  3. #3
    Join Date
    Sep 2004
    Posts
    10
    Thanks ottomatic, but I think I left out an important detail. The database I am trying to close is an external database (where the report resides). The code opens an external database, prints the report and now I want to close that external database--not the one I am currently coding in, which is what DoCmd.Quit does. Any ideas?

  4. #4
    Join Date
    Sep 2003
    Posts
    228
    You created your external database in the object appAccess.

    can't you code:
    Code:
    appAccess.quit
    ?

  5. #5
    Join Date
    Sep 2004
    Posts
    10
    I'm rather new at this--no need to be hateful!

  6. #6
    Join Date
    Sep 2003
    Posts
    228
    Quote Originally Posted by DBNut
    I'm rather new at this--no need to be hateful!
    Not my intent at all...
    You asked for ideas and I gave them to you.
    Everybody is new at some point. Try my suggestions and please let me know if you need any further assistance with this problem.

  7. #7
    Join Date
    Sep 2004
    Posts
    10
    The code worked. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •