ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to call Access function&module in Excel VBA?? (https://www.excelbanter.com/excel-programming/304927-how-call-access-function-module-excel-vba.html)

miao jie

how to call Access function&module in Excel VBA??
 
I have a question for how to call Access procedure/Function in Excel VBA?

Now I have Access, And I define a simple subform for test

data_pool.mdb
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

right now I wanna call the test1() in my Excel file
(add Microsoft Access 10 library in reference)

myExl.xls

Sub Button36_Click()
'Dim cmd As ADODB.Command
'Dim conn As ADODB.Connection

Dim accessObj As Object
Dim ac As Access.Application
Dim path As String

path = ActiveWorkbook.path
path = path & "\data_pool.mdb"
Set accessObj = GetObject(path) ', "Access.Application")
Set ac = accessObj.Application

ac.Run test1
'accessObj.Application.Visible = True

'accessObj.Application.Run Module1.test1

End Sub

I can open this Access in the above code, but I can not run the test1() function here.

anyone can help me out, thanks a lot!!


merjet

how to call Access function&module in Excel VBA??
 
Your code works for me adding quotes around the macro
name, i.e.: ac.Run "test1"

I'd recommend adding the following afterwards:
ac.CloseCurrentDatabase
ac.Quit

HTH,
Merjet





All times are GMT +1. The time now is 09:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com