473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Appending 300 tables into 1 table

I need to append 300 tables (same columns, possible diff formats) onto 1 in Access.

All the tables start with the same name.

I used to have a piece of code that i ran that would simply pull all tables into 1 but have since lost it.

I have to be honest and say i have no VB skills what so ever and i think this is the only way this could be done quickly.
Sep 3 '10 #1

✓ answered by TheSmileyCoder

Here is some example code, you will need to modify as appropriate.
Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateAndAppend()
  2.     'Create table
  3.         Dim tblDef As DAO.TableDef
  4.         Set tblDef = CurrentDb.CreateTableDef("tempTable", , , CurrentProject.Connection)
  5.  
  6.         With tblDef
  7.             .Fields.Append .CreateField("KEY_Hazard", dbLong)
  8.             .Fields.Append .CreateField("mem_Title", dbMemo)
  9.             .Fields.Append .CreateField("ID_CreatedBy", dbLong)
  10.             .Fields.Append .CreateField("dt_Created", dbDate)
  11.         End With
  12.  
  13.         CurrentDb.TableDefs.Append tblDef
  14.  
  15.     'Cleanup
  16.         Set tblDef = Nothing
  17.     Dim oTbl As Object
  18.     For Each oTbl In CurrentData.AllTables
  19.         If Left(oTbl.Name, 5) = "excel" Then
  20.             DoCmd.SetWarnings (False)
  21.             DoCmd.RunSQL "INSERT INTO tempTable ( KEY_Hazard, mem_Title, ID_CreatedBy, dt_Created )" & _
  22.                 " SELECT [Hazard ID], Title, User, Date " & _
  23.                 " FROM [" & oTbl.Name & "]"
  24.             DoCmd.SetWarnings (True)
  25.         End If
  26.     Next
  27.  
  28.     'cleanup
  29.         Set oTbl = Nothing
  30. End Sub
You write that all your tables start with the same letters, in this example I append all tables called "excel....." to the first table I create.

3 2740
tasawer
106 100+
Hi what do you mean by diff formats?

How many coloumns are there and what are the formats?

1. longwinded way would be to create a union query of 300 tables. But this would be view only.. data can only be added to original tables.

2. a.we can store all the table Names into a temporary Table
b. Read the contents of each table
c. Append to new table usng SQL
Sep 3 '10 #2
"Hi what do you mean by diff formats?" What I mean by this is that the excel sheets have different formats in the columns. But they all should be text columns.

I would prefer to use method 2 as i have to do this for several lots of data.

What do i need to put in the module?
Sep 6 '10 #3
TheSmileyCoder
2,322 Expert Mod 2GB
Here is some example code, you will need to modify as appropriate.
Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateAndAppend()
  2.     'Create table
  3.         Dim tblDef As DAO.TableDef
  4.         Set tblDef = CurrentDb.CreateTableDef("tempTable", , , CurrentProject.Connection)
  5.  
  6.         With tblDef
  7.             .Fields.Append .CreateField("KEY_Hazard", dbLong)
  8.             .Fields.Append .CreateField("mem_Title", dbMemo)
  9.             .Fields.Append .CreateField("ID_CreatedBy", dbLong)
  10.             .Fields.Append .CreateField("dt_Created", dbDate)
  11.         End With
  12.  
  13.         CurrentDb.TableDefs.Append tblDef
  14.  
  15.     'Cleanup
  16.         Set tblDef = Nothing
  17.     Dim oTbl As Object
  18.     For Each oTbl In CurrentData.AllTables
  19.         If Left(oTbl.Name, 5) = "excel" Then
  20.             DoCmd.SetWarnings (False)
  21.             DoCmd.RunSQL "INSERT INTO tempTable ( KEY_Hazard, mem_Title, ID_CreatedBy, dt_Created )" & _
  22.                 " SELECT [Hazard ID], Title, User, Date " & _
  23.                 " FROM [" & oTbl.Name & "]"
  24.             DoCmd.SetWarnings (True)
  25.         End If
  26.     Next
  27.  
  28.     'cleanup
  29.         Set oTbl = Nothing
  30. End Sub
You write that all your tables start with the same letters, in this example I append all tables called "excel....." to the first table I create.
Sep 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: freeagent | last post by:
Help!! I am a complete Access newbie and I have to concatenate about 30 tables into one large table. All these tables have the same column headings as each other. For example, I have TABLE...
6
by: Access Newbie | last post by:
I'm using Access 2000 and I'm trying to create a pass-through query to append all the data from a local table to a remote table. I'm using the SQL query editor in MS Access to create the query (I...
1
by: Eli Sidwell | last post by:
I have an Access DB that contains 5 tables for the last 5 years. All 5 tables have the same structure. I wanted to keep each year separate for organizational purposes. But, I want to query all 5...
12
by: Art | last post by:
Hi everyone I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new...
13
by: Shwetabh | last post by:
Hi, I wanted to know if it is possible to do to append two tables into a third table. For example, consider these two tables Table 1...
6
by: buddyr | last post by:
I have two tables: table1 and table2 The fields are the same in both tables. There are duplicate records of table1 and new records not in table1 in table2. I have to add the new records to table1...
5
by: Troels Arvin | last post by:
Hello, Every so often, I'm asked to help people recover data from tables that were either dropped or where to much data was DELETEed. The complications related to restoring data are a problem....
1
by: meacho | last post by:
i'm trying to append 5 tables the problem is that although most of the columns are the same the are on or two or so unique columns in each table. I would like to append the tables creating one table...
6
by: babamc4 | last post by:
I have a main form (mainformlung) with 5 subforms (followupacute, followuplate, biochemresults, haemresults and pftresults). I have copied Allen Browne's Audit Trail code (thanks to Allen Browne)...
3
by: manojspromantr | last post by:
I'm trying to append some data from one table to another table both the table structure are same. I have an attachments field in both tables but it seems that i cannot append the attachments from one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.