Any way to use an Access application in batch mode (no UI)? RRS feed

  • Question

  • We have an Access app where the UI allows a user to click buttons, select files, etc.  Is there any way to call the logic in that app from batch mode without calling the UI?  I know it's possible to call an app from the command line like this:

    "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" "C:\APP.accdb" /x MyFunction

    But I'm not sure how to decouple the UI from the logic.  Has anybody ever done something like that

    Tuesday, October 6, 2015 1:35 PM


  • You can definitely use a batch process to interact with your Access DB.

    ACCESS.EXE /e "c:\YourDB.accdb"

    But what is the ultimate goal?  It almost sounds like you want to do some work on the DB without opening it.  I don't think that's possible.  Do you want to run a nightly process automatically?  If so, please see this link, which describes how to schedule a process.

    Also, if you want to control DB #2 from DB #1, try the sample code here.

    Option Compare Database
    Private Sub Command0_Click()
    Dim accapp As Access.Application
    Set accapp = New Access.Application
    accapp.OpenCurrentDatabase ("C:\Users\xxx\Control one DB from Another\DB.mdb"), False
    accapp.Visible = True
    'Run Macro
    'accapp.DoCmd.RunMacro "RunQueries"
    End Sub
    Public Function UpdateTables1() As Boolean
        Dim app As Access.Application
        'Start a new MSAccess application
        Set app = New Access.Application
        'Open the remote database and run a macro, then close the remote database
        With app
            .OpenCurrentDatabase "C:\ABC\ABC.mdb", True, "the_db_password"
            .Visible = True
            .DoCmd.RunMacro "mcrRefreshPersTable"
        End With
        'Quit the spawned app
        app.Quit acQuitSaveNone
        Set app = Nothing
        'Quit the current app
        Application.Quit acQuitSaveNone
    End Function
    Public Function UpdateTables2() As Boolean
        Dim strSQL As String
        'Delete the current data
        strSQL = "DELETE * FROM tblMyFirstTable"
        CurrentDb.Execute strSQL, dbFailOnError
        strSQL = "DELETE * FROM tblMySecondTable"
        CurrentDb.Execute strSQL, dbFailOnError
        'Get the new data ...
        DoCmd.TransferText acImportDelim, , "tblMyFirstTable", "C:\FullPath\FileName1.txt", False
        DoCmd.TransferText acImportDelim, , "tblMySecondTable", "C:\FullPath\FileName2.txt", False
        'Exit the application
    End Function

    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    • Marked as answer by Ricky Silva Saturday, October 10, 2015 6:30 PM
    Saturday, October 10, 2015 2:23 PM