MS ACCESS, VBA 将外部 MS Access 表导入 SQL server 表

Posted

技术标签:

【中文标题】MS ACCESS, VBA 将外部 MS Access 表导入 SQL server 表【英文标题】:MS ACCESS, VB Import External MS Access table into SQL server table 【发布时间】:2015-06-02 19:21:07 【问题描述】:

我有一个充当用户界面的 Access 数据库。 我在 Access 数据库中有一个链接的 SQL Server 2008 表。在用户界面上有用户选择的各种过滤器/标准(例如日期、外部 MS Access 数据库等。 这些都用于导入数据库。现在,我正在将用户选择的外部 MS Access 数据库导入到用户界面上的内部表中。 我的目标是将这些数据直接导入到 SQL 服务器表中。 这可能吗?

这就是我现在的做法。

 Dim Select_File as string
 Dim varFile as Variant
 Dim DBMonth as String
 DBMonth = Me.Month.Value '<-- this is just the Month that is either Default to current month of what user selects in a combobox on user interface
 ' there is some code here that has the user select the external access database and varFile is = .SelectedItems
 Select_File = varFile     
 DoCmd.TransferDatabase acImport, "Microsoft Access", Select_File, acTable, "Table_" & DBMonth & "_All", "Table"

因此,“表”表包含用户选择的外部 MS Access 数据库中的数据。 我想知道是否有一种简单的方法可以将该数据直接导入 SQL Server 表。 我试图将“表”名称更改为链接的 SQL Server 表,但它只是将其导入到一个名称相同的本地表中,并在其后加上“_1”。

【问题讨论】:

【参考方案1】:

我认为你可以通过执行“追加查询”来做你想做的事。

我不确定名称,所以在这个例子中 [Table] 是包含源数据的原生 Access 表,[SQL Server Table] 是一个链接到服务器上的目标表。

INSERT INTO [SQL Server Table] (Fld1, Fld2, Fld3)
SELECT t.Fld1, t.Fld2, t.Fld3
FROM [Table] AS t

【讨论】:

以上是关于MS ACCESS, VBA 将外部 MS Access 表导入 SQL server 表的主要内容,如果未能解决你的问题,请参考以下文章

MS Access/ VBA:将 if 条件添加到 vba 代码

MS Access 将 xslt 嵌入到 vba

在 C# COM-DLL 项目中使用外部 DLL 用于 MS-Access 使用

从 VBA (MS-Access) 填写 PDF 表单

使用 vba 将 MS Access 查询输出到 Excel

使用 VBA 将 MS Access 报告打印到 .xps 文件