Consulting

Results 1 to 2 of 2

Thread: Closing Excel & Opening Access

  1. #1

    Closing Excel & Opening Access

    Hi,

    I'm running a macro which opens an Access database and then i want it to save the Excel workbook and set the focus on the Access database i've just opened.

    The code below is
    what i've got:

    [vba]Sub PullData_Amend_2()
    Set tk = ActiveWorkbook
    Sheets("Download").Select
    If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
    endRow = Range("A65536").End(xlUp).Row - 1
    Range("F2").Resize(endRow, 1).FormulaR1C1 = "=RC[-1]&""_""&RC[5]"
    Range("F2").Resize(endRow, 1).Copy
    Range("F2").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    MsgBox "Data is now correctly formatted."
    'open PQQ Database and close Excel
    Set acApp = New Access.Application
    acApp.Visible = True
    acApp.OpenCurrentDatabase ("S:\XXXXX\Database.accdb")
    tk.Save
    tk.Close
    End Sub

    [/vba]
    Now the problem is at the end, the macro opens the database ok, then makes it visible. It then saves the workbook and closes Excel - but also closes Access too.

    How can i keep Access open at the end??

    Many thanks

    James
    Last edited by mundo7; 11-06-2009 at 06:54 AM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try using FollowHyperlink to open the database.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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