在VBA中打开另一个.ACCDB文件 [英] Opening up another .ACCDB file in VBA

查看:283
本文介绍了在VBA中打开另一个.ACCDB文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直试图通过我打开的当前数据库的VBA打开另一个现有数据库。我用workspace.openDatabase方法尝试了这个。代码运行,但没有弹出任何内容。我认为这个方法只是引用数据库而不是
打开它。

I have been trying to open up another existing database through VBA of a current database I have open. I tried this with the workspace.openDatabase method. The code runs, but nothing pops up. I think this method just references that database rather than opens it up.

无论如何使用此方法或另一个方法从当前打开另一个数据库。

Is there anyway to open another database from a current with this method, or another one.

这是我正在玩的一些代码。 createworkspace方法中的参数来自Microsoft办公室网站。这是我在这个主题上找到的唯一办法(甚至让我感到困惑)。

Here is some code I was playing around with. The arguments in the createworkspace method are from Microsoft offices website. That is the only recourse that I could find on this topic (and even that confuses me).


    Dim  wrk As Workspace

    Dim  db As Database

    Dim s As String

    Dim wrk As Workspace
    Dim db As Database
    Dim s As String

    s =" Database29.accdb"

   设置  wrk = CreateWorkspace(""," admin","",dbUseJet)

    s = "Database29.accdb"
    Set wrk = CreateWorkspace("", "admin", "", dbUseJet)

推荐答案

OpenDatabase只将数据库加载到内存中供VBA使用,它确实
将数据库打开到Access界面。

OpenDatabase only loads a database into memory for use by VBA, it does notopen the database into the Access interface.

如果要打开另一个数据库,替换当前打开的数据库,可以使用

If you want to open another database, replacing the currently open database, you can use

Application.OpenCurrentDatabase(" Database29.accdb")

Application.OpenCurrentDatabase("Database29.accdb")

请记住,代码会在此之后立即停止运行,因为包含代码的数据库已关闭。

Keep in mind that the code will instantly stop running after that, because the database containing the code has been closed.

如果您不想替换当前数据库,请问自己为什么要在Access界面中打开两个数据库......

If you do not want to replace the current database, ask yourself why you want to open two databases in the Access interface...

这篇关于在VBA中打开另一个.ACCDB文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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