将多个表合并为1 [英] Merge mutiple tables into 1

查看:61
本文介绍了将多个表合并为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个宏,用户可以在其中运行组合Access数据库中所有表的宏。

I'm trying to create a Macro where a user can run a Macro that combines all the tables in an Access database.

1。 Access数据库可能有2个或更多表,并且每个数据库中的表名都不相同。

1. An Access database could have 2 or more tables and the table names are not the same in each database.

2。每个表上的所有列都是相同的。

2. All columns on each tables are the same.

3。我试图使用Union,但表格超过100列,但不起作用。

3. I tried to use Union but the tables has over 100 columns and it won't work.

4。我使用INSERT INTO创建了一个SQL,它可以工作。

4. I created an SQL using INSERT INTO, which works.

INSERT INTO cmbTables 选择*来自XXX1;

INSERT INTO cmbTables  SELECT * From XXX1;

     a。 我需要有关如何循环每个"链接"的帮助table(MSysObject Type = 6)

     a. I need help on how to loop thru each "linked" table (MSysObject Type = 6)

谢谢

JoeH

      

      

推荐答案

循环遍历表:

Dim dbs作为DAO.Database

Dim dbs As DAO.Database

Dim tdf作为DAO。 TableDef

Dim tdf As DAO.TableDef

设置dbs = CurrentDB

Set dbs = CurrentDB

对于dbs.TableDefs中的每个tdf

 如果Len(tdf.Connect)> 0然后

    dbs.Execute(" INSERT INTO cmbTables SELECT * FROM"& tdf.Name&")"

 结束如果

下一个tdf

For each tdf in dbs.TableDefs
  If Len(tdf.Connect) > 0 Then
    dbs.Execute("INSERT INTO cmbTables SELECT * FROM " & tdf.Name &")"
  End If
Next tdf


这篇关于将多个表合并为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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