Joel Adrian Simbahan
Joel Adrian Simbahan

Reputation: 25

VBA - Calling a SUB in an Access file from Excel with Parameters

I am trying to call a subroutine from the Access file "Hey.accdb" using the Excel file "Hoy.xlsm". The subroutine's name is "HelloWorld" with parameter "Para01" which is a string.

Can somebody help me on how I could achieve this?

Here's my coding in the Excel file which does not work:

Sub RunSubinAccesswithPara()

'Open Access file
Set Db = CreateObject("Access.Application")
        Db.OpenCurrentDatabase "D:\Database1\Hey.accdb"
        Db.Visible = True
        Db.AutomationSecurity = msoAutomationSecurityLow
        Db.Execute "HelloWorld('Y')"

End Sub

Any help is appreciated.

Upvotes: 1

Views: 70

Answers (1)

Hubisan
Hubisan

Reputation: 1172

You can use the Application.Run method like so:

DB.Run "HelloWorld", "Y"

Upvotes: 1

Related Questions