Consulting

Results 1 to 3 of 3

Thread: Excel code to close an already openend access database

  1. #1

    Excel code to close an already openend access database

    My goal is to close an already opened access database when Excel Opens. Before anyone asks why I am doing this, its because my excel file has a connection tied to this specific db that is opened.
    The connection data that my excel file contains does not refresh if the db that is trying to connect is openend. Please help I am not too good with vba.

    This one seemed to work but this actually opens the database (a copy) and then closes the copy, not the already opened db:

    Dim accessApp As Object
    Set accessApp = GetObject("c:path", "Access.Application")
    accessApp.docmd.Quit
    Set accessApp = Nothing
    This one does not work and it gives me an error Object required:

     Dim accessApp As Object
     Dim s As String
     s = "c:path"
     Set accessApp = GetObject(s)
     accessApp = docmd.Quit

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "A beggar of love, second hand hero...King of Dreams"
    Posts
    2,602
    you can easily find a solution via googling...

    Sub vbax_54070_Close_Access_DataBase_Quit_Access()
    
        Dim objAccess As Object
        
        On Error Resume Next
    
        Set objAccess = GetObject(, "Access.Application")
    
        If Err.Number = 0 Then
            objAccess.CloseCurrentDatabase 'to close open database
            objAccess.Quit 'to close access application. you dont need previous line if you use this
        Else
            Err.Clear
        End If
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "A beggar of love, second hand hero...King of Dreams"
    Posts
    2,602
    and pls dont duplicate threads
    in Access Forum:

    http://www.vbaexpress.com/forum/show...sing-Excel-vba
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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