本文介绍了源具有密码时的MS Access DoCmd.Transferdatabase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要每月从各种数据库中导入表。导入表后,就将数据库存档,不再查看。

I need to import tables from various databases on a monthly basis. Once the tables are imported, the databases are archived and not looked at again.

我有以下VBA代码,当数据库没有密码保护时,它可以正常工作:

I have the following VBA code which works fine when a DB is not password protected:

Private Sub ImportTheData(ByVal dbImport As String)

DoCmd.SetWarnings False 'Turn OFF display alerts

'Import the full activity & comments table from the Import DB to a temporary table
DoCmd.TransferDatabase acImport, "Microsoft Access", dbImport, acTable, "tbl_Activity", "tbl_TempActivity", True
DoCmd.TransferDatabase acImport, "Microsoft Access", dbImport, acTable, "tbl_Comments", "tbl_TempComments", True

'code continues ...

最后一个参数(storelogin)设置为true,但是似乎无法以编程方式设置这些登录参数(密码)。

The last parameter (storelogin) is set to true, but there seems to be no way to programmatically set those login parameters (password).

当我运行代码时,提示用户输入密码(尽管SetWarnings = False)。由于我每次都导入数十个文件,所以这不是一个可行的解决方案。

When I run the code, the user is prompted to enter the password (despite the SetWarnings = False). As I'm importing dozens of files each time this is not a viable solution.

有没有一种方法可以使用以编程方式导入表DoCmd.TransferDatabase 当文件受密码保护时,如何保护密码?

Is there a way to programatically import tables using DoCmd.TransferDatabase when a file is password protected and if so how?

推荐答案

Public Sub ImportEncr()

    Const dbImport = "D:\DbEncr.accdb"
    Const sPassword = "foobar"

    Dim DB As DAO.Database
    Set DB = DBEngine.OpenDatabase(Name:=dbImport, Options:=False, ReadOnly:=False, Connect:=";PWD=" & sPassword)

    DoCmd.TransferDatabase acImport, "Microsoft Access", dbImport, acTable, "tblEncr", "tblEncr", False

    DB.Close
    Set DB = Nothing

End Sub

StoreLogin 适用于从ODBC数据库链接表。

StoreLogin applies to linking tables from ODBC databases.

这篇关于源具有密码时的MS Access DoCmd.Transferdatabase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 12:05