katerina-p
asked on
Run function / sub in different accdb
Hi all,
I need to, via VBA, call a sub in a different database (accdb). The sub has two optional parameters.
At the moment I've been using the following code, however this doesn't work in Access 2010 runtime (see https://www.experts-exchange.com/questions/28245671/Ms-Access-2007-Error-429-ActiveX-compenent-can't-create-object.html?anchorAnswerId=39512929#a39512929). Line "Set appAccess = CreateObject("Access.Appli cation")" generates error 429 [ActiveX component can't create object]
What other method can I use to call an external function/sub with optional variables?
Many thanks!
K.
I need to, via VBA, call a sub in a different database (accdb). The sub has two optional parameters.
At the moment I've been using the following code, however this doesn't work in Access 2010 runtime (see https://www.experts-exchange.com/questions/28245671/Ms-Access-2007-Error-429-ActiveX-compenent-can't-create-object.html?anchorAnswerId=39512929#a39512929). Line "Set appAccess = CreateObject("Access.Appli
What other method can I use to call an external function/sub with optional variables?
Many thanks!
K.
Public Function fCallForeignProcedure(sDBPath As String, sProc As String, Optional sArgs1 As String, Optional sArgs2 As String)
Dim appAccess As Access.Application
' Create instance of Access Application object.
Set appAccess = CreateObject("Access.Application")
' Open MyDatabaseName.mdb database in Microsoft Access window.
appAccess.OpenCurrentDatabase sDBPath, False
'False so as not to open in exclusive mode
' Run Sub procedure.
Select Case Len(sArgs1)
Case Is = 0
appAccess.Run sProc
Case Is > 0
Select Case Len(sArgs2)
Case Is = 0
appAccess.Run sProc, sArgs1
Case Is > 0
appAccess.Run sProc, sArgs1, sArgs2
End Select
End Select
appAccess.Quit
Set appAccess = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I sometimes forget too
;-)
Jeff
;-)
Jeff
ASKER