Search code examples
ms-accessautomationscriptingautomationanywhere

it is possible to call ms-Access function from outside


I created a public function in an existing Access form and I`m trying to call it from outside the application.Very simple function just created for testing this.

Public Function test1(ByVal test1 As String)
    Dim xlApp As New Excel.Application
    xlApp.Visible = False

    Dim wb As Excel.Workbook
    Set wb = xlApp.Workbooks.Add

    Dim ws As Excel.Worksheet
    Set ws = wb.Worksheets(1)
End Function

I created the connection to it, on Automation Anywhere and I´m trying to call the function created.

Connection String im using:

Provider=Microsoft.ACE.OLEDB.16.0;Data Source="$connection$";Jet OLEDB:Database Password="$pass$"

Tried doing this, without suceed

Select test1("test")
EXEC test1("test1")
EXECUTE test1("test1")

Also with simple '

No way to do this on background so as suggested below I created a sub and called it from an VB Script

Set appAccess = CreateObject("Access.Application")  
appAccess.OpenCurrentDatabase "RUTA ACCESS",,"CONTRASEÑA"
appAccess.UserControl = True
appAccess.Run "generarEtiqueta","numPropuesta","numExp","fileSavePath"   
appAccess.CloseCurrentDatabase
appAccess.Quit

generarEtiqueta is the sub, all the other are arguments


Solution

  • You can create a module in access vba to use it in any form, or independent of form. The function can be called from outside as such:

    Dim appAccess As New Access.Application 
    appAccess.OpenCurrentDatabase ("C:\My Documents\myDatabase.mdb") 
    appAccess.Run "myDatabase.test1", "Pass your argument here"