G
Guest
I have a question for how to call Access procedure/Function in different module in Excel
VBA?
Now I have Access, And I define a simple subform for test in different sub module:
data_pool.mdb.module1
Sub test1()
Dim conDatabase As ADODB.Connection
Set conDatabase = Application.CurrentProject.Connection
Dim SQL As String
SQL = "update country set scale = scale + 1 where country = ""dd"" "
conDatabase.Execute (SQL)
'conDatabase.CommitTrans
'Call table_conversion
End Sub
data_pool.mdb.module2
Sub test1()
msgbox "ddd"
End Sub
right now I wanna call the test1() in my Excel file
(add Microsoft Access 10 library in reference)
myExl.xls
Sub Button36_Click()
Dim accessObj As Object
Dim ac As Access.Application
Dim path As String
path = ActiveWorkbook.path
path = path & "\data_pool.mdb"
' Create instance of Access Application object.
Set ac = CreateObject("Access.Application")
' Open WizCode database in Microsoft Access window.
ac.OpenCurrentDatabase path, Exclusive:=True
' Exclusive = false means can not open access if it is opened
'ac.Run "module1.test1"
ac.Run "test1"
'ac.Run "[module1.test1]"
ac.CloseCurrentDatabase
ac.Quit
End Sub
If the different Function name in different module in Access, the code is run well
but I set same function name in different module in Access, the Run method can not work. (
In Access, I can set the same function name in different module and run well)
anyone can help me out, thanks a lot
VBA?
Now I have Access, And I define a simple subform for test in different sub module:
data_pool.mdb.module1
Sub test1()
Dim conDatabase As ADODB.Connection
Set conDatabase = Application.CurrentProject.Connection
Dim SQL As String
SQL = "update country set scale = scale + 1 where country = ""dd"" "
conDatabase.Execute (SQL)
'conDatabase.CommitTrans
'Call table_conversion
End Sub
data_pool.mdb.module2
Sub test1()
msgbox "ddd"
End Sub
right now I wanna call the test1() in my Excel file
(add Microsoft Access 10 library in reference)
myExl.xls
Sub Button36_Click()
Dim accessObj As Object
Dim ac As Access.Application
Dim path As String
path = ActiveWorkbook.path
path = path & "\data_pool.mdb"
' Create instance of Access Application object.
Set ac = CreateObject("Access.Application")
' Open WizCode database in Microsoft Access window.
ac.OpenCurrentDatabase path, Exclusive:=True
' Exclusive = false means can not open access if it is opened
'ac.Run "module1.test1"
ac.Run "test1"
'ac.Run "[module1.test1]"
ac.CloseCurrentDatabase
ac.Quit
End Sub
If the different Function name in different module in Access, the code is run well
but I set same function name in different module in Access, the Run method can not work. (
In Access, I can set the same function name in different module and run well)
anyone can help me out, thanks a lot