Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

In Access, how to merge quickly two linked tables (originally views from SQL Server) in a local Access table


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, then simply link all 12 tables.

Then assuming you have a local table of the same structure? then you can run a append query like this:

Dim strFromTable  As String
Dim strToTable    As String
Dim i             As Integer
Dim strSQL        As String

strFromTable = "dbo_tblData"   ' our 1 - 12 tables
strToTable = "tblLocalTable"

For i = 1 To 12
   strSQL = "INSERT INTO " & strToTable & _
           " SELECT * FROM " & strFromTable & i
   Debug.Print "appending table " & strFromTable
   CurrentDb.Execute strSQL, dbFailOnError
Next i

Now above assumes that the 12 linked tables are named dbo_tblData1, then dbo_tblData2 etc.

If you don't have such a naming convention, then you could change above code to use a different table name that you supply.

You also could consider writing code to create the "linked" table on the fly, but its probably just as easy to link the 12 tables one time, and then above will work.

the above of course pulls all 12 tables into ONE table in Access. You could certainly modify the above to pull each table "from" into a local table.

eg this:

   strSQL = "INSERT INTO " & strToTable & i & _
           " SELECT * FROM " & strFromTable & i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...