从Excel调用Access Sub [英] Calling Access Sub from Excel

查看:112
本文介绍了从Excel调用Access Sub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Excel调用Access数据库中的子例程.然后,此子调用许多其他子例程,所有这些子例程都包含在数据库中.我不建议这样做,但由于其他原因,Excel需要成为此的前端.我试过了:

I'm trying to call a subroutine in an Access database from Excel. This sub then call a number of other subroutines, all contained within the database. I saw a number of other posts where this was discouraged, but for reasons, Excel needs to be the front-end for this. I tried:

Sub TestRun()
        Dim acObj As Access.Application
        Set acObj = CreateObject("Access.Application")
        acObj.Application.Visible = True
        acObj.OpenCurrentDatabase "C:\testMDB\TEST.mdb", False, "password"
        acObj.Application.Run ("TestRunAccess")
End Sub

该数据库是带有密码的工作组的一部分-以这种方式运行它仍会提示您输入密码.我对Access不太熟悉-我将如何去做?我需要包括哪些参考?

The database is part of a workgroup with a password - running it this way still prompts for the password. I'm not very familiar with Access - how would I go about doing this? What references would I need to include?

推荐答案

那是:

''Reference: Microsoft Access x.x Object Library
Dim acObj As New Access.Application
''Set acObj = CreateObject("Access.Application")
acObj.Application.Visible = True
acObj.OpenCurrentDatabase "C:\testMDB\TEST.mdb",,"ADatabasePassword"
acObj.Application.Run "TestRunAccess"

在这种情况下,如果您希望避免引用出现问题,则可能更喜欢使用后期绑定:

You may prefer to use late binding if you wish to avoid problems with references, in which case:

Dim acObj As Object
Set acObj = CreateObject("Access.Application")
acObj.Application.Visible = True
acObj.OpenCurrentDatabase "C:\testMDB\TEST.mdb",,"ADatabasePassword"
acObj.Application.Run "TestRunAccess"

这篇关于从Excel调用Access Sub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆